开发者

Path problem in JSP with getRequestDispatcher

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

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

That's working fin开发者_如何学Goe, 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.


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


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 '\'.


(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>


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


RequestDispatcher rd = getServletContext().getRequestDispatcher("/NewPurchase.do");
        rd.forward(request, response) ;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜