我如何从 DispatchServlet 映射文件夹(资源文件夹)中排除
我的 web.xml 是: http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" 版本="2.5"> TestStruts2
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>
org.apache.tiles.definition.DefinitionsFactory.DEFINITIONS_CONFIG
</param-name>
<param-value>
/WEB-INF/tiles-defs.xml
</param-value>
</context-param>
<listener>
<listener-class>org.apache.tiles.web.startup.TilesListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>/WEB-INF/Templates/Jsp/index.jsp</welcome-file>
</welcome-file-list>
我正在使用 Spring 和 Tiles2.1 我的资源文件夹位于 /WEB-INF/Templates/Resources/ DispatcherServlet 设置为映射所有(“/”)。我想排除“Resources”文件夹(包含图像、css),因为 tomcat 不显示图像和 css。它说的是这样的内容:,,找不到......的映射。”
My web.xml is:
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
TestStruts2
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>
org.apache.tiles.definition.DefinitionsFactory.DEFINITIONS_CONFIG
</param-name>
<param-value>
/WEB-INF/tiles-defs.xml
</param-value>
</context-param>
<listener>
<listener-class>org.apache.tiles.web.startup.TilesListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>/WEB-INF/Templates/Jsp/index.jsp</welcome-file>
</welcome-file-list>
I'm using Spring and Tiles2.1
My resource folder is in /WEB-INF/Templates/Resources/
DispatcherServlet is set to map all ("/"). I want to exclude "Resources" folder (that contains images,css) because tomcat doesn't show images and css. It sayes something like: ,,No mapping found for ...."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 WEB-INF 中取出图像、CSS 等资源。
“WEB-INF”不适用于静态资源,它用于包含程序代码(JSP、类文件、库等)并防止外部访问。将资源放入项目存档(.war、.ear)中并不是一个好的做法,因为您的包部署起来会非常繁重。
意味着你的dispatcherServlet映射请求 http://host/applicationName/*
你可以把你的资源放入vhost/host。 com/httpdocs/images 的主机独立于您的 java 应用程序。说:
http://host/myimages/
并且可以从您的模板(jsps)相对访问,
因此您的包会更小并且快速部署;)
Take the resources like images, css etc. out of WEB-INF.
"WEB-INF" is not for static resources and it's used to contain program code (JSPs, class files, libraries, etc.) and prevent access from outside. It is not a good practice to put your resources into your project archive (.war, .ear) because your package will be very heavy weight to deploy.
means that your dispatcherServlet maps the requests http://host/applicationName/*
You can put your resources into vhost/host.com/httpdocs/images of your host independent from your java application. say:
http://host/myimages/
and relatively accessable from your templeates (jsps)
therefore your packages would be smaller and speedy to deploy ;)