problem in custom tags

R

roohbir

Hi,
I have a program in which I have a basic jsp page with a text field
and a submit button. The idea is that when a user enters his name and
hits the button it should take him to another page which displays
"Hello user".
I have made a JSP page but don't knwo how to connect it with the
servlet. The name of the servlet is MyOwnCustomTag. The servlet and
jsp page are displayed underneath:

<html><head><title>Registration Page</title></head>
<body>

<%@ taglib uri="/myOwnTLD" prefix="myowntag"%>

<form action="MyOwnCustomTag" method='post'>
<table>
<tr>
<td> Enter Name: </td>
<td><input type='text' size=15 name='name'
value='<myowntag:requestParameter property="name"/>'>
</td>
</tr>

</table>
</p>
<br>
<input type='submit' value='Submit'>
<input type='hidden' name='action' value='register-action'>
</form>

</body></html>

================================================================

import javax.servlet.ServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class MyOwnCustomTag extends TagSupport {
private String property;

public void setProperty(String property) {
this.property = property;
}
public int doStartTag() throws JspException {
ServletRequest req = pageContext.getRequest();
String value = req.getParameter(property);

try {
pageContext.getOut().print("Hello " + value);
}
catch(java.io.IOException ex) {
throw new JspException(ex.getMessage());
}
return SKIP_BODY;
}
}
=========================================

Help would be really appreciated.
Ros
 
J

Joshua Cranmer

Andrew said:
It might help to ask a question.

Andrew T.

I think the problem is he doesn't know how to integrate the page with
the servlet, per paragraph 2.
 
K

Kai Schwebke

roohbir said:
I have made a JSP page but don't knwo how to connect it with the
servlet. The name of the servlet is MyOwnCustomTag. The servlet and ....
public class MyOwnCustomTag extends TagSupport {
....

You wrote a custom tag, not a servlet. The tag may be embedded in a
JSP called by your form page, but cannot be called directly.

A good book covering these topics is Falkner/Jones "Servlets and Java
Server Pages". It's free to download here:
http://www.theserverside.com/tt/books/addisonwesley/ServletsJSP/index.tss


Kai
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top