This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 6657
    
    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
 
Consider Paul's rocket mass heater.
 
subject: How to call a servlet from a JSP
 
Similar Threads
To call a servlet from a JSP
Servlet to Jsp parameter calling
jsp error page from servlet
jsp error page from servlet
JSP to Servlet call