您的位置:首页 > 编程语言 > C语言/C++

C/C++中Static的作用详述

2011-12-14 14:03 260 查看
spring reset 访问静态文件方式

1 在XML里配置,这里配置就是需要你明确你的网站可以访问哪些静态文件

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
<url-pattern>*.js</url-pattern>
<url-pattern>*.gif</url-pattern>
<url-pattern>*.jpg</url-pattern>
<url-pattern>*.png</url-pattern>
</servlet-mapping>

2 rewrite

<urlrewrite default-match-type="wildcard">
<!-- url 重写,以便访问静态文件如gif,css,js等文件 -->
<rule>
<condition operator="notequal" next="and" type="request-uri">.*.jsp</condition>
<condition operator="notequal" next="and" type="request-uri">.*.jspx</condition>
<condition operator="notequal" next="and" type="request-uri">.*.json</condition>
<condition operator="notequal" next="and" type="request-uri">.*.do</condition>
<from>^(/.*\..*)$</from>
<to>/static$1</to>
</rule>
</urlrewrite>

3 以文件夹方式保存

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/static/*</url-pattern>
</servlet-mapping>

and in each url (image,css) you need to put /static in front of it...

---------------------------------------
被@PostConstruct修饰的方法会在服务器加载Servle的时候运行,并且只会被服务器执行一次。PostConstruct在构造函数之后执行,init()方法之前执行。PreDestroy()方法在destroy()方法执行执行之后执行

@PostConstruct
public void init() {}

@PreDestroy
public void destroy() {}

public void setDao(TestDao dao) {
this.dao = dao;
}

------------------------------------------

07-十二月-2011 09:55:55.447 WARN [ ] PageNotFound - No mapping found for HTTP request with URI [/WEB-INF/views/sinykk.html] in DispatcherServlet with name 'ModelViewController'

<servlet-mapping>
<servlet-name>ModelViewController</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
原因:

<url-pattern>/</url-pattern>换成<url-pattern>*.do</url-pattern>

When you set the url-pattern to /* then all requests will be sent to that DispatcherServlet, which includes the request for JSP rendering. Though it's not true, it's sometimes useful to think of the InternalResourceView (and derived like JstlView) as another HTTP request, since that way you'll see why a request for the JSP is getting picked up by the DispatcherServlet.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: