aspose file tools
The moose likes Servlets and the fly likes how to call JSP from Servlet 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: 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é
Marshal

Joined: Nov 24, 2005
Posts: 14361

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


[SCBCD Wall of Fame] [My Blog]
All roads lead to JavaRanch
Help Japan. Make a donation.
Ulf Dittmer
Marshal

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



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


Android appsImageJ pluginsJava web charts
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: 461

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: 461

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: 461

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: 461

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