• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Christian Lee
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty sure you can't jsp:include or forward to a servlet, only between JSPs.
Dave
 
Christian Lee
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic