Servlets 在的URL模式上映射Servlet时加载资源文件失败/

Servlets 在的URL模式上映射Servlet时加载资源文件失败/,servlets,resources,web.xml,url-pattern,Servlets,Resources,Web.xml,Url Pattern,我使用NetBeans和Tomcat 7.0.4.2,希望将我的项目的URL地址从localhost:8080/Servlet更改为localhost:8080/。在web.xml中,我将servlet URL地址从/servlet更改为/ 问题是我现在无法加载资源文件,并且无法在浏览器控制台日志中获取错误: Failed to load resource: the server responded with a status of 404 (Not Found) (11:45:14:149

我使用NetBeans和Tomcat 7.0.4.2,希望将我的项目的URL地址从
localhost:8080/Servlet
更改为
localhost:8080/
。在
web.xml
中,我将servlet URL地址从
/servlet
更改为
/

问题是我现在无法加载资源文件,并且无法在浏览器控制台日志中获取错误:

  Failed to load resource: the server responded with a status of 404 (Not Found) (11:45:14:149 | error, network)
  at src/main/webapp/scripts/aui-min_2.0.0.js
资源文件的路径是
src/main/webapp/scripts
,在JSP文件中我使用这个路径


web.xml


Servlet
socialgraphui.Servlet
Servlet
/
30

默认servlet使用url模式
/
,该servlet能够加载其他servlet未映射的静态资源。当你切换到这种模式时,它就停止工作了。因此,您应该保持一个servlet映射


Servlet
/Servlet
如果要从索引页面开始,请使用
配置中列出的
index.jsp
。索引页面可以使用以下命令重定向到servlet

response.sendRedirect(request.getContextPath()+“/Servlet”);
要加载静态资源,请使用如下servlet上下文路径



感谢Roman的回复,但在tomcat以循环方式部署我的项目之后,无法停止OK,请重新部署它。感谢Roman,但它仍然不起作用。这是我的新web.xml,现在我可以在localhost:8080/address上加载我的源代码,但是使用这个解决方案,我不能将变量从Servlet传递到index.jsp文件。在Servlet类中,我试图替换request.getRequestDispatcher(“index.jsp”).forward(请求,响应);通过response.sendRedirect(“/Servlet”);在processRequest方法中,但仍然无法传递变量。
index.jsp
应该只有code
。但是您可以调度到另一个页面,以避免无休止的循环。部署中没有
src
目录。任何依赖于它存在的代码都是错误的。相关: