• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic