tags:

views:

104

answers:

4

In my application, I am using jsp include as :-

<jsp:include page="/jsp/selectRoom/listRoom.jsp" />

That's working fine, but when I include the same jsp in my servlet as :-

RequestDispatcher rd = getServletContext().getRequestDispatcher("//jsp//selectRoom//listRoom.jsp") ;
rd.include(request, response) ;

That's not working. Am I making some syntactical mistake?


As log details are not required, i am removing the log details from my post.

+2  A: 

There's a paranthesis missing:

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

And I'm not quite sure if you really need those double slashes.

Best wishes,
Fabian

halfdan
haha, nice.. who would ever assume a compilation error.. :)
Bozho
even RequestDispatcher rd = getServletContext().getRequestDispatcher("/jsp/selectRoom/listRoom.jsp") ; is not working.
rits
A: 

I agree with my predecessors. There is no need to escape the / characters with another / in the path. Java String does not interpret the '/' in any special way. It's only '\' that need to be escaped with an additional '\'.

maciejs
Yes, but you aren't answering at all. You're only confirming. Just use comments for this.
BalusC
A: 

(Provided you use tomcat) - How about going to your /tomcat/work/Catalina/localhost/yourwebapp/org/.../jsp/selectedRoom/yourjsp_jsp.java and copy-paste the RequestDispatcher code from there (you will have to search a little). It should work.

That .java file is the servlet that tomcat has generated from your jsp.

The jsp in question is the one where you successfully use <jsp:include>

Bozho
A: 

are you sure that's not working. I did a simple webapp with the following code:

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class Test extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
     // TODO Auto-generated method stub
     RequestDispatcher rd = getServletContext().getRequestDispatcher("/jsp/selectRoom/listRoom.jsp") ;
     rd.include(request, response) ;
    }
}

and that work perfectly

Xavier Combelle