| Author |
how to call JSP from Servlet
|
Syskata Mitev
Ranch Hand
Joined: Aug 23, 2006
Posts: 51
|
posted

0
|
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: 14672
|
posted

0
|
|
request.getRequestDispatcher("/pathyourjsp").forward(request, response);
|
[My Blog]
All roads lead to JavaRanch
|
 |
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35258
|
posted

0
|
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 apps – ImageJ plugins – Java web charts
|
 |
Syskata Mitev
Ranch Hand
Joined: Aug 23, 2006
Posts: 51
|
posted

0
|
|
Thank's a lot. it's working;
|
 |
Hira Iqbal
Greenhorn
Joined: Jul 29, 2010
Posts: 26
|
posted

0
|
|
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: 503
|
posted

0
|
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
|
posted

0
|
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: 503
|
posted

0
|
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
|
posted

0
|
<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: 503
|
posted

0
|
|
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
|
posted

0
|
|
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: 503
|
posted

0
|
|
then, please post the full details like servlet code in the new topic.. this topic, is going out of context..
|
 |
 |
|
|
subject: how to call JSP from Servlet
|
|
|