开发者

Pass in proper path for Servlet in .jsp

I have a .jsp file which has to submit the request to Re开发者_如何学PythonsultServlet

but i am getting the error

HTTP Status 404 - /project1/jsp//ResultServlet

The problem is that my ResultServlet is in /project1/src/ResultServlet

Can you tell me what changes i need to make to the action field in .jsp so that it starts looking in folder src instead of folder jsp


I understand that you'd like to use a relative URL to the servlet in <form action> of the JSP. First you need to determine the full URL of both the JSP and the Servlet and then extract the relative URL to the Servlet from the JSP.

Let's assume that your JSP is on http://example.com/context/jsp/page.jsp and that your Servlet is on http://example.com/context/src/servlet. So to reach the Servlet from the JSP you have to go one level up ../ so that you lands in http://example.com/context and finally go from there to src/servlet.

<form action="../src/servlet">

Alternatively, you can also use the context path if you don't want to be dependent on the location/URL of the JSP:

<form action="${pageContext.request.contextPath}/src/servlet">
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜