Failed to load resource files when mapping Servlet on URL pattern of / -
i use netbeans , tomcat 7.0.4.2 , change url address of project localhost:8080/servlet
localhost:8080/
. in web.xml
changed servlet url address <url-pattern>/servlet</url-pattern>
<url-pattern>/</url-pattern>
.
the problem can't load resource files , errors in browser console log:
failed load resource: server responded status of 404 (not found) (11:45:14:149 | error, network) @ src/main/webapp/scripts/aui-min_2.0.0.js
the path resource files src/main/webapp/scripts
, in jsp file use path
<script type="text/javascript" src="scripts/aui-min_2.0.0.js"></script>
web.xml
<?xml version="1.0" encoding="utf-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <servlet> <servlet-name>servlet</servlet-name> <servlet-class>socialgraphui.servlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>servlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> </web-app>
the url pattern /
is used default servlet capable of loading static resources isn't mapped other servlets. when switched pattern it's stopped working. so, should keep servlet mapping.
<servlet-mapping> <servlet-name>servlet</servlet-name> <url-pattern>/servlet</url-pattern> </servlet-mapping>
if want start index page use index.jsp
listed in <welcome-file-list>
configuration. index page can redirect servlet using
response.sendredirect(request.getcontextpath() +"/servlet");
to load static resource use servlet context path that
<script type="text/javascript" src="${pagecontext.request.contextpath}/scripts/aui-min_2.0.0.js"></script>
Comments
Post a Comment