aspose file tools*
The moose likes Servlets and the fly likes How to call a servlet from a JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to call a servlet from a JSP" Watch "How to call a servlet from a JSP" New topic
Author

How to call a servlet from a JSP

Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
I have a web application where I use JSP's as output I want a JSP to go to a servlet to drive a function. Can you call a servlet from a JSP?
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Provide a url to the servlet and click it. Or if you want to dynamically update something on your page you need to use AJAX.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

yes, you can.

Three ways do it,

1. By using <jsp:forward> tag

2. If JSP has html <form> element, you can add a attribute called action="<url>" and give URL which match <servlet-mapping> <url-pattern> in web.xml of your application.

3. AJAX call as John said.


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
Got it to work using forward thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to call a servlet from a JSP