This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes how to call JSP from Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

how to call JSP from Servlet

Syskata Mitev
Ranch Hand

Joined: Aug 23, 2006
Posts: 51
i have this servlet :


and i wont to run some JSP from this servlet.
thanks.

[BSouther: Added UBB CODE tags]
[ April 10, 2007: Message edited by: Ben Souther ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

request.getRequestDispatcher("/pathyourjsp").forward(request, response);


[My Blog]
All roads lead to JavaRanch
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41034
    
  43
You probably want something like this:



Use "include" instead of "forward" if more JSPs are involved, or if the servlet produces output as well.


Ping & DNS - my free Android networking tools app
Syskata Mitev
Ranch Hand

Joined: Aug 23, 2006
Posts: 51
Thank's a lot. it's working;
Hira Iqbal
Greenhorn

Joined: Jul 29, 2010
Posts: 26
I have to do the oppsite. Have to call servlet from jsp what should i write in action tag of my form on jsp?
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

Hira Iqbal wrote:I have to do the oppsite. Have to call servlet from jsp what should i write in action tag of my form on jsp?


Just the URL mapping of the servlet given in your web.xml..


Regards, Prasad
SCJP 5 (93%)
Hira Iqbal
Greenhorn

Joined: Jul 29, 2010
Posts: 26
I am not much familiar with xml handling so tell me a little easy way please
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

Hira Iqbal wrote:I am not much familiar with xml handling so tell me a little easy way please

I have told nothing about xml handling.. can you post your web.xml here, i will tell you what to give in action tag of the form..
Hira Iqbal
Greenhorn

Joined: Jul 29, 2010
Posts: 26
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Controller</servlet-name>
<servlet-class>assignment.Controller</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>/Controller</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

This is the xml file.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

Give Controller in action tag of form element in JSP.. so, that after submitting the JSP page, the servlet will be called..
Hira Iqbal
Greenhorn

Joined: Jul 29, 2010
Posts: 26
I had done it but it did not worked. I got exception that request resource is not available.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

then, please post the full details like servlet code in the new topic.. this topic, is going out of context..
 
wood burning stoves
 
subject: how to call JSP from Servlet
 
Similar Threads
"MVC" controller servlet
Solution for repeating function in all servlets.
GET Method Working But POST is not
user authentication and dao
if() is not working