Author
Servlet call using Hyperlink
udhayan kumar
Greenhorn
Joined: Jan 28, 2010
Posts: 16
Hi,
How can i call servlet using hyperlink
Provide good example.
Please help me out.
Thanks.
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
By clicking on it?
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Bosun Bello
Ranch Hand
Joined: Nov 06, 2000
Posts: 1506
Just put the string that maps to your servlet in the hyperlink.
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
udhayan kumar
Greenhorn
Joined: Jan 28, 2010
Posts: 16
Paul Sturrock wrote: By clicking on it?
Yup
udhayan kumar
Greenhorn
Joined: Jan 28, 2010
Posts: 16
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
Joined: Apr 14, 2004
Posts: 10336
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
Joined: Jan 28, 2010
Posts: 16
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
Joined: Nov 06, 2000
Posts: 1506
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
Joined: Sep 29, 2008
Posts: 12617
posted Jul 01, 2010 06:30:03
0
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.
subject: Servlet call using Hyperlink