servlet注意路径

今天遇到这样的错误,折腾了半天:

java.lang.IllegalStateException org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407) org.apache.catalina.servlets.DefaultServlet.serveResource(DefaultServlet.java:701) org.apache.catalina.servlets.DefaultServlet.doGet(DefaultServlet.java:339) org.apache.catalina.servlets.DefaultServlet.doPost(DefaultServlet.java:418) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) com.assets.view.LoginFilter.doFilter(LoginFilter.java:39)

原因:

在jsp页面上使用了
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/ backend/";
%>

而web.xml里servlet配置是:
<servlet>
<servlet-name>loginServlet</servlet-name>
<servlet-class>com.assets.view.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>loginServlet</servlet-name>
<url-pattern>/ loginServlet</url-pattern>
</servlet-mapping>

解决方法:

把jsp的根路径设置与web.xml一致。

你可能感兴趣的:(java,Web,jsp)