aspose file troubles
The moose likes Servlets and the fly likes how to call JSP from Servlet The Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


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: 50
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: 12765
request.getRequestDispatcher("/pathyourjsp").forward(request, response);

[SCWCD Wall of Fame] [SCBCD Wall of Fame] [My Blog]
All roads lead to JavaRanch
Ulf Dittmer
Sheriff

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



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

cewolf - Java web chartsMy Android appsImageJ Plugins
Syskata Mitev
Ranch Hand

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

Joined: Jul 29, 2010
Posts: 6
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: 108
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..

This message was edited 1 time. Last update was at by Prasad Krishnegowda


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

Joined: Jul 29, 2010
Posts: 6
I am not much familiar with xml handling so tell me a little easy way please

This message was edited 1 time. Last update was at by Hira Iqbal

Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 108
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: 6
<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: 108
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: 6
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: 108
then, please post the full details like servlet code in the new topic.. this topic, is going out of context..

This message was edited 2 times. Last update was at by Prasad Krishnegowda

 
 
subject: how to call JSP from Servlet
 
hibernate profiler