Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

problem in custom tags

Thread view: 
roohbir - 18 Mar 2007 15:12 GMT
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
Andrew Thompson - 18 Mar 2007 15:19 GMT
..
> Help would be really appreciated.

It might help to ask a question.

Andrew T.
Joshua Cranmer - 18 Mar 2007 20:04 GMT
> ..
>> Help would be really appreciated.
>
> 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.
Kai Schwebke - 18 Mar 2007 20:14 GMT
> 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
roohbir - 18 Mar 2007 20:42 GMT
> > 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
[quoted text clipped - 10 lines]
>
> Kai

Thanks a lot Kai and Joshua. Much appreciated.
Ros


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.