Bookmark Topic Watch Topic
  • New Topic

how to call JSP from Servlet

 
Syskata Mitev
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
request.getRequestDispatcher("/pathyourjsp").forward(request, response);
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Report post to moderator
You probably want something like this:



Use "include" instead of "forward" if more JSPs are involved, or if the servlet produces output as well.
 
Syskata Mitev
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thank's a lot. it's working;
 
Hira Iqbal
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 671
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
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..
 
Hira Iqbal
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Report post to moderator
I am not much familiar with xml handling so tell me a little easy way please
 
Prasad Krishnegowda
Ranch Hand
Posts: 671
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Report post to moderator
<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
Posts: 671
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Report post to moderator
I had done it but it did not worked. I got exception that request resource is not available.
 
Prasad Krishnegowda
Ranch Hand
Posts: 671
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
then, please post the full details like servlet code in the new topic.. this topic, is going out of context..
 
    Bookmark Topic Watch Topic
  • New Topic