aspose file tools*
The moose likes Servlets and the fly likes Servlet call using Hyperlink Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet call using Hyperlink" Watch "Servlet call using Hyperlink" New topic
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: 1510
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: 1510
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

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet call using Hyperlink