Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet call using Hyperlink

 
udhayan kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How can i call servlet using hyperlink

Provide good example.

Please help me out.

Thanks.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By clicking on it?
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just put the string that maps to your servlet in the hyperlink.
 
udhayan kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:By clicking on it?


Yup
 
udhayan kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bosun Bello wrote:Just put the string that maps to your servlet in the hyperlink.


The servlet class should contain which method then doPost or doGet??
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
udhayan kumar wrote:
Bosun Bello wrote:Just put the string that maps to your servlet in the hyperlink.


The servlet class should contain which method then doPost or doGet??


If you are clikcing on a hyperlink then it is a GET.
 
udhayan kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
udhayan kumar wrote:
Bosun Bello wrote:Just put the string that maps to your servlet in the hyperlink.


The servlet class should contain which method then doPost or doGet??



Servlet class get method:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Servler example</title>");
out.println("<body>");
out.println("<h1>Package class simple servlet<h1>");
out.println("</body>");
out.println("</html>");
}

prompt.jsp:

click me

Web.xml:

<servlet>
<description></description>
<display-name>hello</display-name>
<servlet-name>hello</servlet-name>
<servlet-class>pack1.hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>

wats wrong in d above code..

But i m not getting d result..

Regards,
Udhay
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the link that you are trying to use to invoke this servlet. You should dynamicaly get your context path and then append your servlet name in your mapping.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic