jQuery in Action, 2nd edition*
The moose likes JSP and the fly likes jsp:include a servlet and the servlet forwards to a jsp file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp:include a servlet and the servlet forwards to a jsp file" Watch "jsp:include a servlet and the servlet forwards to a jsp file" New topic
Author

jsp:include a servlet and the servlet forwards to a jsp file

Christian Lee
Greenhorn

Joined: Feb 26, 2002
Posts: 6
hello
i have a jsp:include and forward problem
the scenario is as follows.
i have two JSP files and one servlet files.
In the First File say "index.jsp" i am including one servlet file say "ServletTest". and in the included servlet file i am forwarding to the other jsp file say "test.jsp" but i am getting an error javax.servlet.ServletException
i am working on j2ee ri 1.3.1... please reply soon me really stuck
thanks alot !!
-----------------------------------------------
<!--content of index.jsp:-->
<jsp:include page="/ServletTest"/>
------------------------------------------------
//content of ServletTest.java:
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;

/**
* @Author heinzli
*/
public class ServletTest extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
System.out.println("servlet");

RequestDispatcher rd = getServletContext().getRequestDispatcher("/test.jsp");

rd.forward(request,response);
}


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
doPost(request,response);
}
}
------------------------------------------------
<!--content of test.jsp:-->
<br>i m return file.<br>

----------------------------------------------
<!--web.xml-->
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>ServletTest</servlet-name>
<servlet-class>ServletTest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletTest</servlet-name>
<url-pattern>/ServletTest</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

heinzli
[ May 21, 2002: Message edited by: Christian Lee ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I'm pretty sure you can't jsp:include or forward to a servlet, only between JSPs.
Dave
Christian Lee
Greenhorn

Joined: Feb 26, 2002
Posts: 6
Thanks.
But it works well on WebLogic 61 that a jsp file first.jsp uses <jsp:include page="aServlet"> and this included servlet forwards another jsp file second.jsp.
As a result,second.jsp becomes the part of first.jsp.
Now I wanna test it on J2EE RI 1.3 but it cannot work that the included jsp content is blank.
Weblogic 61 and J2EE RI 1.3 which one is right ?
Zakaria Haque
Ranch Hand

Joined: Jan 02, 2002
Posts: 60
Originally posted by David O'Meara:
I'm pretty sure you can't jsp:include or forward to a servlet, only between JSPs.

I think you are confusing static and dynamic includes. Since jsp:include uses RequestDispatcher( the spec does not mandate using RequestDiaptcher, so teh jsp engine MAY use some proprietary mechanism) for dynamic contents, you can include pretty much anything exsiting in the webapp domain.


tobe bondhu nouka bherao<br />shonabo gaan aj shara raat
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: jsp:include a servlet and the servlet forwards to a jsp file