http://www.oschina.net/code/snippet_170632_46774javascript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
beans
xmlns
=
"http://www.springframework.org/schema/beans"
xmlns:aop
=
"http://www.springframework.org/schema/aop"
xmlns:cache
=
"http://www.springframework.org/schema/cache"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:context
=
"http://www.springframework.org/schema/context"
xmlns:p
=
"http://www.springframework.org/schema/p"
xmlns:task
=
"http://www.springframework.org/schema/task"
xmlns:tx
=
"http://www.springframework.org/schema/tx"
xmlns:lang
=
"http://www.springframework.org/schema/lang"
xmlns:mvc
=
"http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">
<
bean
id
=
"propertyConfigurer"
class
=
"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
>
<
property
name
=
"locations"
>
<
list
>
<
value
>classpath:jdbc.properties</
value
>
<
value
>classpath:mail.properties</
value
>
</
list
>
</
property
>
</
bean
>
<!-- 若是 sprinmvc 和 spring ioc 掃描的包有重合就會把類初始化2次 context:component-scan -->
<!-- beans能夠引用springmvc的類,可是springmvc不能引用spring的類 -->
<!-- Springmvc 的ioc容器中的bean能夠引用spring 的ioc容器的bean,反之不能夠 -->
<
context:component-scan
base-package
=
"com.sniper.springmvc.hibernate.*,com.sniper.springmvc.scheduler"
>
<!-- 不掃描的帶有這些註解的類 -->
<
context:exclude-filter
type
=
"annotation"
expression
=
"org.springframework.stereotype.Controller"
/>
<
context:exclude-filter
type
=
"annotation"
expression
=
"org.springframework.web.bind.annotation.ControllerAdvice"
/>
</
context:component-scan
>
<!-- 配置數據源,其餘框架 -->
<!-- 分庫配置 master -->
<
bean
id
=
"dataSource_main"
class
=
"com.mchange.v2.c3p0.ComboPooledDataSource"
>
<
property
name
=
"driverClass"
value
=
"${jdbc.driverClass}"
/>
<
property
name
=
"jdbcUrl"
value
=
"${jdbc.jdbcUrl}"
/>
<
property
name
=
"user"
value
=
"${jdbc.user}"
/>
<
property
name
=
"password"
value
=
"${jdbc.password}"
/>
<
property
name
=
"idleConnectionTestPeriod"
value
=
"${c3p0.idleConnectionTestPeriod}"
/>
<
property
name
=
"preferredTestQuery"
value
=
"${c3p0.preferredTestQuery}"
/>
<
property
name
=
"testConnectionOnCheckin"
value
=
"${c3p0.testConnectionOnCheckin}"
/>
<
property
name
=
"testConnectionOnCheckout"
value
=
"${c3p0.testConnectionOnCheckout}"
/>
<
property
name
=
"maxPoolSize"
value
=
"${c3p0.maxPoolSize}"
/>
<
property
name
=
"minPoolSize"
value
=
"${c3p0.minPoolSize}"
/>
<
property
name
=
"initialPoolSize"
value
=
"${c3p0.initialPoolSize}"
/>
<
property
name
=
"acquireIncrement"
value
=
"${c3p0.acquireIncrement}"
/>
</
bean
>
<!-- 分庫配置 slave -->
<
bean
id
=
"dataSource_salve_1"
parent
=
"dataSource_main"
>
<
property
name
=
"jdbcUrl"
value
=
"${jdbc.jdbcUrl}"
/>
</
bean
>
<!-- 配置數據源路由器 -->
<
bean
id
=
"dataSourceRouter"
class
=
"com.sniper.springmvc.datasource.DataSourceRouter"
>
<
property
name
=
"targetDataSources"
>
<
map
>
<
entry
key
=
"master"
value-ref
=
"dataSource_main"
/>
<
entry
key
=
"salve_a"
value-ref
=
"dataSource_salve_1"
/>
</
map
>
</
property
>
<!-- 默認數據源集合 -->
<
property
name
=
"defaultTargetDataSource"
ref
=
"dataSource_main"
/>
</
bean
>
<!-- 呢目的會話工廠bean(spring整合hinernate的核心入口) -->
<
bean
id
=
"sessionFactory"
class
=
"org.springframework.orm.hibernate4.LocalSessionFactoryBean"
>
<!-- 配置路由數據源 -->
<
property
name
=
"dataSource"
ref
=
"dataSourceRouter"
/>
<
property
name
=
"configLocation"
value
=
"classpath:hibernate.cfg.xml"
/>
<!-- 註解 -->
<
property
name
=
"packagesToScan"
>
<
list
>
<
value
>com.sniper.springmvc.model</
value
>
</
list
>
</
property
>
</
bean
>
<!-- hibernate事務管理器,用來在service層面上實現事務管理,實現平臺無關行 -->
<
bean
id
=
"transactionManager"
class
=
"org.springframework.orm.hibernate4.HibernateTransactionManager"
>
<
property
name
=
"sessionFactory"
ref
=
"sessionFactory"
/>
</
bean
>
<!-- 事物通知 -->
<!-- rollback-for回滾事物,果存在一個事務,則支持當前事務。若是沒有事務則開啓 -->
<!-- aopalliance-1.0 須要這個包不然報錯,這個包在struts裏面 -->
<
tx:advice
id
=
"txAdvice"
transaction-manager
=
"transactionManager"
>
<
tx:attributes
>
<
tx:method
name
=
"save*"
propagation
=
"REQUIRED"
isolation
=
"DEFAULT"
rollback-for
=
"Exception"
/>
<
tx:method
name
=
"delete*"
propagation
=
"REQUIRED"
isolation
=
"DEFAULT"
rollback-for
=
"Exception"
/>
<
tx:method
name
=
"update*"
propagation
=
"REQUIRED"
isolation
=
"DEFAULT"
rollback-for
=
"Exception"
/>
<
tx:method
name
=
"batch*"
propagation
=
"REQUIRED"
isolation
=
"DEFAULT"
rollback-for
=
"Exception"
/>
<
tx:method
name
=
"execute*"
propagation
=
"REQUIRED"
isolation
=
"DEFAULT"
rollback-for
=
"Exception"
/>
<
tx:method
name
=
"get*"
propagation
=
"REQUIRED"
isolation
=
"DEFAULT"
read-only
=
"true"
rollback-for
=
"Exception"
/>
<
tx:method
name
=
"load*"
propagation
=
"REQUIRED"
isolation
=
"DEFAULT"
read-only
=
"true"
rollback-for
=
"Exception"
/>
<
tx:method
name
=
"find*"
propagation
=
"REQUIRED"
isolation
=
"DEFAULT"
read-only
=
"true"
rollback-for
=
"Exception"
/>
<!-- <tx:method name="*" propagation="NOT_SUPPORTED" isolation="DEFAULT"
read-only="true"/> -->
<
tx:method
name
=
"*"
propagation
=
"REQUIRED"
isolation
=
"DEFAULT"
/>
</
tx:attributes
>
</
tx:advice
>
<!-- 切入點通知 -->
<!-- 日誌記錄 -->
<
bean
id
=
"logger"
class
=
"com.sniper.springmvc.advice.Logger"
/>
<!-- EhCache library setup -->
<
bean
id
=
"ehcache"
class
=
"org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
p:config-location
=
"classpath:ehcache.xml"
/>
<
bean
id
=
"cacheManager"
class
=
"org.springframework.cache.ehcache.EhCacheCacheManager"
p:cache-manager-ref
=
"ehcache"
/>
<!-- 自定義生成緩存key -->
<
bean
id
=
"surveyKey"
class
=
"com.sniper.springmvc.cache.SurveyKey"
></
bean
>
<
cache:advice
id
=
"cacheAdvice"
cache-manager
=
"cacheManager"
key-generator
=
"surveyKey"
>
<!-- -->
<
cache:caching
cache
=
"SurveyAdminRight"
>
<!-- 緩存方法 保存的key -->
<
cache:cacheable
method
=
"getC*"
/>
<
cache:cacheable
method
=
"loadC*"
/>
<
cache:cacheable
method
=
"findC*"
/>
<!-- 刪除緩存的方法 就是當執行下面方法的時候除掉緩存 須要配合aop切入點才管用 -->
<
cache:cache-evict
method
=
"save*"
all-entries
=
"true"
/>
<
cache:cache-evict
method
=
"update*"
all-entries
=
"true"
/>
<
cache:cache-evict
method
=
"delete*"
all-entries
=
"true"
/>
<
cache:cache-evict
method
=
"clear*"
all-entries
=
"true"
/>
<
cache:cache-evict
method
=
"toggle*"
all-entries
=
"true"
/>
<
cache:cache-evict
method
=
"move*"
all-entries
=
"true"
/>
<
cache:cache-evict
method
=
"batch*"
all-entries
=
"true"
/>
</
cache:caching
>
</
cache:advice
>
<
aop:config
>
<!-- order 值越大優先值越低 -->
<!-- 事務切入點通知 -->
<
aop:advisor
advice-ref
=
"txAdvice"
pointcut
=
"execution(* *..*Service.*(..))"
order
=
"1"
/>
<!-- 緩存切入點通知 -->
<
aop:advisor
advice-ref
=
"cacheAdvice"
pointcut="(execution(* *..*Service.getC*(..))
or execution(* *..*Service.findC*(..))
or execution(* *..*Service.loadC*(..))
or execution(* *..*Service.save*(..))
or execution(* *..*Service.update*(..))
or execution(* *..*Service.delete*(..))
or execution(* *..*Service.move*(..))
or execution(* *..*Service.toggle*(..))
or execution(* *..*Service.clear*(..)))
and !bean(myUserDetail)
"
order
=
"0"
/>
<!-- logger切面 -->
<
aop:aspect
id
=
"loggerAspect"
ref
=
"logger"
order
=
"0"
>
<
aop:around
method
=
"record"
pointcut="(execution(* *..*Service.save*(..))
or execution(* *..*Service.update*(..))
or execution(* *..*Service.delete*(..))
or execution(* *..*Service.batch*(..))
or execution(* *..*Service.new*(..))
or execution(* *..*Service.move*(..))
or execution(* *..*Service.clear*(..))
or execution(* *..*Service.toggle*(..)))
and !bean(logService)
" />
</
aop:aspect
>
</
aop:config
>
<
bean
id
=
"mailSender"
class
=
"org.springframework.mail.javamail.JavaMailSenderImpl"
>
<
property
name
=
"defaultEncoding"
value
=
"${mail.smtp.encoding}"
/>
<
property
name
=
"host"
value
=
"${mail.smtp.host}"
/>
<
property
name
=
"username"
value
=
"${mail.smtp.username}"
/>
<
property
name
=
"password"
value
=
"${mail.smtp.password}"
/>
<
property
name
=
"javaMailProperties"
>
<
props
>
<!-- 是否開啓驗證 -->
<
prop
key
=
"mail.smtp.auth"
>${mail.smtp.auth}</
prop
>
<
prop
key
=
"mail.debug"
>true</
prop
>
<!-- 設置發送延遲 -->
<
prop
key
=
"mail.smtp.timeout"
>${mail.smtp.timeout}</
prop
>
</
props
>
</
property
>
</
bean
>
<!-- 設置計劃人物掃描 -->
<
task:annotation-driven
/>
<!--加載 -->
<
bean
id
=
"springContextHelper"
class
=
"com.sniper.springmvc.security.SpringContextUtil"
></
bean
>
</
beans
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
package
com.sniper.springmvc.sitemesh3;
import
org.sitemesh.builder.SiteMeshFilterBuilder;
import
org.sitemesh.config.ConfigurableSiteMeshFilter;
public
class
MySiteMeshFilter
extends
ConfigurableSiteMeshFilter {
@Override
protected
void
applyCustomConfiguration(SiteMeshFilterBuilder builder) {
builder.addDecoratorPath(
"/admin/**"
,
"/WEB-INF/template/admin/main.jsp"
)
.addExcludedPath(
"/admin/login**"
)
.addExcludedPath(
"/admin/admin-print**"
)
.addExcludedPath(
"/admin/file-upload**"
)
.addDecoratorPath(
"/*"
,
"/WEB-INF/template/home/main.jsp"
)
.addExcludedPath(
"/myfiles/*"
);
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
beans
xmlns
=
"http://www.springframework.org/schema/beans"
xmlns:aop
=
"http://www.springframework.org/schema/aop"
xmlns:cache
=
"http://www.springframework.org/schema/cache"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:context
=
"http://www.springframework.org/schema/context"
xmlns:p
=
"http://www.springframework.org/schema/p"
xmlns:task
=
"http://www.springframework.org/schema/task"
xmlns:tx
=
"http://www.springframework.org/schema/tx"
xmlns:lang
=
"http://www.springframework.org/schema/lang"
xmlns:mvc
=
"http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<!--須要進行 spring整合springmvc麼 仍是須要加入spring的ioc容器 是否須要在web.xml中配置springioc容器的ContextLoaderListener
1.須要:一般狀況下,相似於數據源,事務,整合其餘框架都是放在spring配置文件中(而不是放在springmv裏面) 2.不須要都放在springmvc的配置文件中,也能夠分多個Spring
的配置文件而後import 節點導入其餘的配置文件 實際上 -->
<
context:component-scan
base-package
=
"com.sniper.springmvc"
>
<!-- 不掃描的帶有這些註解的類 -->
<
context:exclude-filter
type
=
"annotation"
expression
=
"org.springframework.stereotype.Service"
/>
</
context:component-scan
>
<!-- 配置 freemarker解析器 -->
<!-- http://www.osblog.net/wangxp/140.html -->
<
bean
class
=
"org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"
>
<
property
name
=
"viewClass"
value
=
"org.springframework.web.servlet.view.freemarker.FreeMarkerView"
/>
<
property
name
=
"suffix"
value
=
""
/>
<
property
name
=
"viewNames"
value
=
"*.ftl"
/>
<
property
name
=
"prefix"
value
=
""
/>
<
property
name
=
"cache"
value
=
"false"
/>
<
property
name
=
"contentType"
value
=
"text/html;charset=UTF-8"
/>
<
property
name
=
"exposeRequestAttributes"
value
=
"true"
/>
<
property
name
=
"exposeSessionAttributes"
value
=
"true"
/>
<
property
name
=
"exposeSpringMacroHelpers"
value
=
"true"
/>
<!-- 此變量值爲pageContext.request, 頁面使用方法:base.contextPath -->
<
property
name
=
"requestContextAttribute"
value
=
"base"
/>
<
property
name
=
"order"
value
=
"200"
/>
</
bean
>
<
bean
id
=
"fmXmlEscape"
class
=
"freemarker.template.utility.XmlEscape"
></
bean
>
<
bean
id
=
"freemarkerConfig"
class
=
"org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"
>
<
property
name
=
"templateLoaderPath"
value
=
"/WEB-INF/template/"
/>
<
property
name
=
"defaultEncoding"
value
=
"UTF-8"
/>
<
property
name
=
"freemarkerVariables"
>
<
map
>
<
entry
key
=
"xml_escape"
value-ref
=
"fmXmlEscape"
/>
</
map
>
</
property
>
<
property
name
=
"freemarkerSettings"
>
<
props
>
<
prop
key
=
"tag_syntax"
>auto_detect</
prop
>
<
prop
key
=
"template_update_delay"
>5</
prop
>
<
prop
key
=
"defaultEncoding"
>UTF-8</
prop
>
<
prop
key
=
"url_escaping_charset"
>UTF-8</
prop
>
<
prop
key
=
"locale"
>zh_CN</
prop
>
<
prop
key
=
"boolean_format"
>true,false</
prop
>
<
prop
key
=
"datetime_format"
>yyyy-MM-dd HH:mm:ss</
prop
>
<
prop
key
=
"date_format"
>yyyy-MM-dd</
prop
>
<
prop
key
=
"time_format"
>HH:mm:ss</
prop
>
<
prop
key
=
"number_format"
>0.######</
prop
>
<
prop
key
=
"whitespace_stripping"
>true</
prop
>
<!--空值處理<prop key="classic_compatible">true</prop> -->
<!-- <prop key="auto_import">/ftl/tags/index.ftl as p,/ftl/spring.ftl
as s</prop> -->
</
props
>
</
property
>
</
bean
>
<!-- 配置試圖解析器 -->
<
bean
class
=
"org.springframework.web.servlet.view.InternalResourceViewResolver"
>
<
property
name
=
"prefix"
value
=
"/WEB-INF/template/"
/>
<!-- 下面2個都不容許設置 -->
<!-- <property name="suffix" value="" /> -->
</
bean
>
<
bean
id
=
"localeResolver"
class
=
"org.springframework.web.servlet.i18n.CookieLocaleResolver"
>
<
property
name
=
"cookieName"
value
=
"clientlanguage"
/>
<
property
name
=
"cookieMaxAge"
value
=
"-1"
/>
</
bean
>
<!-- id 必須是 messageSource不然出錯 -->
<!-- 使用jstl 資源國際化的設置 -->
<
bean
id
=
"messageSource"
class
=
"org.springframework.context.support.ResourceBundleMessageSource"
>
<
property
name
=
"basename"
value
=
"i18n"
/>
</
bean
>
<!--配置試圖 beanNameViewResolver解析器 ,使用試圖的名字來解析試圖 -->
<!-- 經過order來設置 試圖解析器的優先級,只要配置都會被默認的小 -->
<
bean
class
=
"org.springframework.web.servlet.view.BeanNameViewResolver"
>
<
property
name
=
"order"
value
=
"100"
/>
</
bean
>
<!-- 配置直接轉發的頁面 -->
<!-- 直接響應轉發的頁面不通過handler的方法 ,若是不加上下面的配置之前的 url都會失效 -->
<
mvc:view-controller
path
=
"/success"
view-name
=
"success"
/>
<!-- 取消對靜態資源的解釋,這樣能夠直接訪問靜態資源,這裏判斷訪問資源是否被映射過 -->
<!-- 這樣不會出現找不到匹配資源的狀況 -->
<
mvc:default-servlet-handler
/>
<!-- 靜態文件映射 -->
<
mvc:resources
location
=
"/myfiles/"
mapping
=
"/myfiles/**"
/>
<!-- 下面是我學習是寫的能夠把大家沒有的刪除便可 -->
<!-- 在實際開發中都一般須要配置 mvc:annotion-driven 標籤 -->
<!-- 加上這個配置就不會除了mvc以外的url都不能使用 -->
<!-- 做用有不少會住測三個bean 支持實例對錶單參數類型轉換 支持不少類型註解數據類型的格式化 -->
<!-- -->
<
mvc:annotation-driven
/>
<!-- 下面的寫法可使用自定義轉換器,自定義類型轉換器和系統類型轉換器一塊兒使用 -->
<!-- <mvc:annotation-driven conversion-service="conversionService" /> -->
<!-- 配置 conversionService -->
<!-- org.springframework.context.support.ConversionServiceFactoryBean -->
<
bean
id
=
"conversionService"
class
=
"org.springframework.format.support.FormattingConversionServiceFactoryBean"
>
<
property
name
=
"converters"
>
<
set
>
<!-- 使用 @Component註冊 用spring掃描 -->
<
ref
bean
=
"userConverter"
/>
</
set
>
</
property
>
</
bean
>
<!-- 驗證 -->
<
bean
id
=
"validationFactoryBean"
class
=
"org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"
>
</
bean
>
<!-- 配置 SessionLocaleResolver -->
<
bean
id
=
"localResolver"
class
=
"org.springframework.web.servlet.i18n.SessionLocaleResolver"
/>
<!-- 下面的攔截器能夠指定url開始的 -->
<!-- 配置連接修改語言環境的 攔截器 org.springframework.web.servlet.i18n.LocaleChangeInterceptor -->
<
mvc:interceptors
>
<!-- 配置自定義攔截器,controller的使用時間 -->
<
mvc:interceptor
>
<
mvc:mapping
path
=
"/**"
/>
<
mvc:exclude-mapping
path
=
"/myfiles/**"
/>
<
mvc:exclude-mapping
path
=
"/verify**"
/>
<
bean
class
=
"com.sniper.springmvc.interceptions.RunTimeInterceptor"
/>
<!-- 連接改變語言環境的session攔截器 -->
</
mvc:interceptor
>
<
mvc:interceptor
>
<
mvc:mapping
path
=
"/**"
/>
<
mvc:exclude-mapping
path
=
"/myfiles/**"
/>
<
mvc:exclude-mapping
path
=
"/verify**"
/>
<!-- 連接改變語言環境的session攔截器 -->
<
bean
class
=
"com.sniper.springmvc.interceptions.MyLocaleChangeInterceptor"
/>
</
mvc:interceptor
>
<
mvc:interceptor
>
<!-- 攔截器管用的路徑 -->
<
mvc:mapping
path
=
"/springmvc"
/>
<!-- 那個攔截器使用此條規則 -->
<
bean
class
=
"com.sniper.springmvc.interceptions.SecondInterceptor"
/>
<!-- 攔截器無論用的路徑 -->
<!-- <mvc:exclude-mapping path="/abc"/> -->
</
mvc:interceptor
>
</
mvc:interceptors
>
<!-- 上傳文件配置 -->
<
bean
id
=
"multipartResolver"
class
=
"org.springframework.web.multipart.commons.CommonsMultipartResolver"
>
<
property
name
=
"defaultEncoding"
value
=
"UTF-8"
/>
<
property
name
=
"maxUploadSize"
value
=
"10485760"
/>
</
bean
>
<!-- 配置錯誤處理頁面 -->
<!-- 經過 SimpleMappingExceptionResolver處理錯誤頁面 -->
<
bean
class
=
"org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"
>
<!-- 更改試圖中exception的名稱 -->
<!-- <property name="exceptionAttribute" value="ex"></property> <property
name="exceptionMappings"> <props> <prop key="java.lang.ArrayIndexOutOfRoundsException"></prop>
</props> </property> -->
<!-- <property name="exceptionMappings"> <props> <prop key="java.lang.Throwable">500</prop>
</props> </property> <property name="warnLogCategory" value="WARN"></property>
<property name="defaultErrorView" value="500"></property> <property name="defaultStatusCode"
value="500"></property> <property name="statusCodes"> <props> <prop key="404">404</prop>
<prop key="500">500</prop> </props> </property> -->
</
bean
>
</
beans
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
package
com.sniper.springmvc.action.home;
import
java.util.Date;
import
java.util.Map;
import
org.springframework.stereotype.Controller;
import
org.springframework.web.bind.annotation.RequestBody;
import
org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.ResponseBody;
import
com.sniper.springmvc.model.SystemConfig;
@Controller
public
class
Index
extends
BaseAction<SystemConfig> {
@RequestMapping
(
"/"
)
public
String index(Map<String, Object> map) {
System.out.println(model.getClass());
System.out.println(
"執行個人次數"
);
return
"home/index/index.jsp"
;
}
/**
* 數據下載例子
*
* @param map
* @return
*/
@RequestMapping
(
"goto"
)
public
String download(Map<String, Object> map) {
map.put(
"path"
,
"/approot/soft/ffmpeg-2.5.2.tar.bz2"
);
return
"redirect:download"
;
}
@RequestMapping
(
"toupload"
)
public
String upload() {
return
"home/index/index.jsp"
;
}
@RequestMapping
(
"freemarker"
)
public
String freemarker() {
return
"home/index/index.ftl"
;
}
@ResponseBody
public
String reponseBody(
@RequestBody
String body) {
// 返回客戶端一個字符串
System.out.println(body);
return
"aa"
+
new
Date();
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
<!
DOCTYPE
html>
<
html
lang
=
"zh-cn"
>
<
head
>
<
meta
charset
=
"utf-8"
>
<
title
>登陸</
title
>
<
base
href
=
"${baseHref.baseHref}"
>
<
meta
name
=
"viewport"
content
=
"width=device-width, initial-scale=1.0"
>
<
meta
http-equiv
=
"X-UA-Compatible"
content
=
"IE=edge"
>
<
script
type
=
"text/javascript"
src
=
"myfiles/js/jquery-1.11.1.min.js"
></
script
>
<
script
type
=
"text/javascript"
src
=
"myfiles/Plugin/Bootstrap/js/bootstrap.min.js"
></
script
>
<
link
href
=
"myfiles/Plugin/Bootstrap/css/bootstrap.min.css"
media
=
"screen"
rel
=
"stylesheet"
type
=
"text/css"
>
<
link
href
=
"myfiles/Plugin/Bootstrap/css/bootstrap-theme.min.css"
media
=
"screen"
rel
=
"stylesheet"
type
=
"text/css"
>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="myfiles/Plugin/Bootstrap/js/html5shiv.min.js"></script>
<![endif]-->
<
script
type
=
"text/javascript"
src
=
"myfiles/js/jquery.backstretch.min.js"
></
script
>
<
style
type
=
"text/css"
>
.form-signin {
margin: 0 auto;
max-width: 330px;
padding: 15px;
}
</
style
>
</
head
>
<
body
>
<
div
class
=
"container"
>
<
form
data-status
=
''
class
=
"form-signin"
role
=
"form"
name
=
"login"
action
=
"login_check"
method
=
"post"
>
<
h2
class
=
"form-signin-heading"
>登陸</
h2
>
<
input
type
=
"hidden"
name
=
"${_csrf.parameterName}"
value
=
"${_csrf.token}"
/>
<#if loginError??>
<
div
class
=
"alert alert-warning alert-dismissible"
role
=
"alert"
>
<
button
type
=
"button"
class
=
"close"
data-dismiss
=
"alert"
>
<
span
aria-hidden
=
"true"
>×</
span
><
span
class
=
"sr-only"
>Close</
span
>
</
button
>
${loginError}
</
div
>
</#if>
<
div
class
=
"form-group input-group-lg"
>
<
label
for
=
"username"
>用戶名</
label
>
<
input
type
=
"text"
id
=
"username"
value
=
"${lastLoginName!''}"
name
=
"username"
class
=
"form-control"
placeholder
=
""
required autofocus>
</
div
>
<
div
class
=
"form-group input-group-lg"
>
<
label
for
=
"password"
>密碼</
label
>
<
input
id
=
"password"
type
=
"password"
name
=
"password"
class
=
"form-control"
placeholder
=
""
name
=
""
required>
</
div
>
<#if loginNum?? && loginNum?eval gt 300 >
<
div
class
=
"form-group input-group-lg"
>
<
label
for
=
"verifycode"
class
=
"col-sm-2 control-label sr-only"
>
驗證碼
</
label
>
<
input
type
=
"text"
name
=
"sessionVerifyName"
style
=
" display: inline;width: 44%; float: left;"
placeholder
=
""
id
=
"verifycode"
class
=
"form-control"
>
<
img
alt
=
""
style
=
"cursor: pointer; margin-left:2%"
src
=
"verify"
class
=
"fl"
>
</
div
>
</#if>
<
div
class
=
"form-group input-group-lg"
>
<
label
class
=
""
>
<
input
type
=
"checkbox"
name
=
"remember-me"
> Remember me
</
label
>
</
div
>
<
button
class
=
"btn btn-lg btn-primary btn-block"
type
=
"submit"
>
登陸
</
button
>
<
p
class
=
"text-muted pull-right"
><
a
href
=
"password/getPassword"
>忘記密碼?</
a
></
p
>
</
form
>
</
div
>
<!-- /container -->
<
script
language
=
"javascript"
>
$(function() {
$('form img').click(function() {
fleshVerify();
});
});
function fleshVerify() {
var timenow = new Date().getTime();
var src = $('form img').attr("src");
var indexof = src.indexOf("?");
if (indexof != -1) {
src = src.substring(0, src.indexOf("?"));
}
$('form img').attr("src", src + '?d=' + timenow);
}
</
script
>
</
body
>
</
html
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!
DOCTYPE
HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<
html
>
<
head
>
<
title
>My JSP 'index.jsp' starting page</
title
>
<
meta
http-equiv
=
"pragma"
content
=
"no-cache"
>
<
meta
http-equiv
=
"cache-control"
content
=
"no-cache"
>
<
meta
http-equiv
=
"expires"
content
=
"0"
>
<
meta
http-equiv
=
"keywords"
content
=
"keyword1,keyword2,keyword3"
>
<
meta
http-equiv
=
"description"
content
=
"This is my page"
>
</
head
>
<
body
>
</
body
>
</
html
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
beans:beans
xmlns
=
"http://www.springframework.org/schema/security"
xmlns:beans
=
"http://www.springframework.org/schema/beans"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">
<
global-method-security
pre-post-annotations
=
"enabled"
/>
<
http
pattern
=
"/myfiles/**"
security
=
"none"
/>
<
http
pattern
=
"/attachments/**"
security
=
"none"
/>
<
http
pattern
=
"/verify**"
security
=
"none"
/>
<
http
disable-url-rewriting
=
"true"
use-expressions
=
"false"
entry-point-ref
=
"authenticationProcessingFilterEntryPoint"
>
<!-- 匿名受權 -->
<
access-denied-handler
error-page
=
"/WEB-INF/template/error/error_no_right.jsp"
/>
<!--auto-config = true 則使用from-login. 若是不使用該屬性 則默認爲http-basic(沒有session). -->
<!-- lowercase-comparisons:表示URL比較前先轉爲小寫。 -->
<!-- path-type:表示使用Apache Ant的匹配模式。 -->
<!--access-denied-page:訪問拒絕時轉向的頁面。 -->
<!-- access-decision-manager-ref:指定了自定義的訪問策略管理器。 -->
<
intercept-url
pattern
=
"/**"
access
=
"IS_AUTHENTICATED_ANONYMOUSLY"
/>
<
intercept-url
pattern
=
"/admin**"
access
=
"ROLE_ADMIN"
/>
<!-- <form-login /> -->
<!-- username-parameter="j_username" password-parameter="j_password" login-processing-url="j_spring_security_check" -->
<!-- <form-login login-page="/admin/login" authentication-failure-url="/admin/login?error=true"
default-target-url="/admin" username-parameter="username" password-parameter="password"
/> -->
<!--login-page:指定登陸頁面。 -->
<!-- login-processing-url:指定了客戶在登陸頁面中按下 Sign In 按鈕時要訪問的 URL。 -->
<!-- authentication-failure-url:指定了身份驗證失敗時跳轉到的頁面。 -->
<!-- default-target-url:指定了成功進行身份驗證和受權後默認呈現給用戶的頁面。 -->
<!-- always-use-default-target:指定了是否在身份驗證經過後老是跳轉到default-target-url屬性指定的URL。 -->
<!-- /j_spring_security_logout, 註銷頁面 -->
<!--logout-url:指定了用於響應退出系統請求的URL。其默認值爲:/j_spring_security_logout。 -->
<!-- logout-success-url:退出系統後轉向的URL。 -->
<!-- invalidate-session:指定在退出系統時是否要銷燬Session。 -->
<
logout
logout-success-url
=
"/admin/login"
logout-url
=
"/logout"
delete-cookies
=
"JSESSIONID"
/>
<!-- 表單中的name是 remember_me -->
<!-- services-ref="rememberMeServices" -->
<
remember-me
remember-me-parameter
=
"_spring_security_remember_me"
remember-me-cookie
=
"SPRING_SECURITY_REMEMBER_ME_COOKIE"
/>
<!-- <http-basic /> -->
<
csrf
disabled
=
"false"
/>
<
headers
disabled
=
"false"
>
<
cache-control
/>
<
content-type-options
/>
<
hsts
/>
<!-- <frame-options /> -->
<
xss-protection
/>
<!-- 靜態頭部信息 -->
<!-- <header name="Content-Security-Policy" value="default-src 'self'"
/> <header name="Content-Security-Report-Only" value="default-src 'self'"
/> -->
</
headers
>
<!-- 檢測session是否可用的地址 max-sessions=1配合單用戶登陸最大session個數=1 -->
<!-- session-fixation-protection 解決session僞造 -->
<!-- error-if-maximum-exceeded 解決單一登陸,不提出第一個登陸 -->
<!-- max-sessions:容許用戶賬號登陸的次數。範例限制用戶只能登陸一次。 -->
<!-- 此值表示:用戶第二次登陸時,前一次的登陸信息都被清空。 -->
<!-- 須要在web.xml添加監聽器 org.springframework.security.web.session.HttpSessionEventPublisher -->
<
session-management
session-fixation-protection
=
"none"
>
<
concurrency-control
max-sessions
=
"1"
error-if-maximum-exceeded
=
"true"
/>
</
session-management
>
<!-- 設置驗證filter -->
<!-- <custom-filter ref="csrfFilter" before="CSRF_FILTER" /> -->
<
custom-filter
ref
=
"myLoginFilter"
before
=
"FORM_LOGIN_FILTER"
/>
<
custom-filter
ref
=
"mySniperFilter"
before
=
"FILTER_SECURITY_INTERCEPTOR"
/>
<!-- cas單點登陸配置 -->
<!-- <custom-filter ref="myLogoutFilter" before="LOGOUT_FILTER"/> <custom-filter
ref="myCasFilter" before="CAS_FILTER"/> -->
</
http
>
<!-- <beans:bean id="requestDataValueProcessor" class="org.springframework.security.web.servlet.support.csrf.CsrfRequestDataValueProcessor"
/> <beans:bean id="csrfFilter" class="org.springframework.security.web.csrf.CsrfFilter">
<beans:constructor-arg> <beans:bean class="org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository">
<beans:property name="headerName" value="X-SECURITY" /> </beans:bean> </beans:constructor-arg>
</beans:bean> -->
<
beans:bean
id
=
"rememberMeServices"
class
=
"org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices"
>
<
beans:constructor-arg
name
=
"userDetailsService"
ref
=
"myUserDetail"
/>
<
beans:constructor-arg
name
=
"key"
value
=
"remember_me"
/>
<
beans:property
name
=
"alwaysRemember"
value
=
"true"
/>
<
beans:property
name
=
"tokenValiditySeconds"
value
=
"86400"
/>
<
beans:property
name
=
"parameter"
value
=
"remember_me"
/>
<
beans:property
name
=
"cookieName"
value
=
"spring_security_remember_me_cookies"
/>
</
beans:bean
>
<!-- 配置過濾器 -->
<
beans:bean
id
=
"mySniperFilter"
class
=
"com.sniper.springmvc.security.MyFilterSecurityInterceptor"
>
<!-- 用戶擁有的權限 -->
<
beans:property
name
=
"authenticationManager"
ref
=
"authenticationManager"
/>
<!-- 用戶是否擁有所請求資源的權限 -->
<
beans:property
name
=
"accessDecisionManager"
ref
=
"myAccessDecisionManagerBean"
/>
<!-- 資源與權限對應關係 -->
<
beans:property
name
=
"securityMetadataSource"
ref
=
"securityMetadataSource"
/>
</
beans:bean
>
<!-- 認真管理器,實現用戶認證的入口,主要實現USerDetailsService 接口便可 -->
<
authentication-manager
alias
=
"authenticationManager"
>
<
authentication-provider
user-service-ref
=
"myUserDetail"
>
<!-- 由於用戶登陸自定義,密碼加密在自定義裏面加密過了因此這裏不用設置加密 -->
<!-- <password-encoder hash="md5"> -->
<!-- <salt-source user-property="username"/> <salt-source user-property="password"/> -->
<!-- </password-encoder> -->
</
authentication-provider
>
</
authentication-manager
>
<!-- 讀取用戶的密碼,角色信息,是否鎖定,帳號是否過時 -->
<
beans:bean
id
=
"myUserDetail"
class
=
"com.sniper.springmvc.security.MyUserDetailsService"
>
<
beans:constructor-arg
name
=
"adminUserService"
ref
=
"adminUserService"
/>
</
beans:bean
>
<!-- 訪問決策其,決定那個用戶具備的角色,是否足夠權限訪問 -->
<
beans:bean
id
=
"myAccessDecisionManagerBean"
class
=
"com.sniper.springmvc.security.myAccessDecisionManagerBean"
/>
<!-- 資源數據定義,將全部的資源和權限對應關係創建起來,及定義木易資源能夠被大寫橘色訪問 -->
<
beans:bean
id
=
"securityMetadataSource"
class
=
"com.sniper.springmvc.security.MySecurityMetadataSource"
>
<
beans:property
name
=
"adminRightService"
ref
=
"adminRightService"
/>
</
beans:bean
>
<!-- 自定義登陸filter -->
<
beans:bean
id
=
"myLoginFilter"
class
=
"com.sniper.springmvc.security.MyUsernamePasswordAuthenticationFilter"
>
<!-- 處理登陸 -->
<
beans:property
name
=
"filterProcessesUrl"
value
=
"/login_check"
/>
<!-- 處理登陸成功以後的處理 -->
<
beans:property
name
=
"authenticationSuccessHandler"
ref
=
"loginLogAuthenticationSuccessHandler"
/>
<!-- 驗證失敗 -->
<
beans:property
name
=
"authenticationFailureHandler"
ref
=
"simpleUrlAuthenticationFailureHandler"
/>
<
beans:property
name
=
"authenticationManager"
ref
=
"authenticationManager"
/>
<!-- 注入用戶dao -->
<
beans:property
name
=
"adminUserService"
ref
=
"adminUserService"
/>
<!-- <beans:property name="rememberMeServices" ref="rememberMeServices"
/> -->
</
beans:bean
>
<!-- 登陸成功後跳轉頁面 -->
<
beans:bean
id
=
"loginLogAuthenticationSuccessHandler"
class
=
"org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler"
>
<
beans:property
name
=
"defaultTargetUrl"
value
=
"/admin/"
/>
</
beans:bean
>
<!-- 登陸失敗後跳轉頁面 -->
<
beans:bean
id
=
"simpleUrlAuthenticationFailureHandler"
class
=
"org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"
>
<!-- 能夠配置相應的跳轉方式。屬性forwardToDestination爲true採用forward false爲sendRedirect -->
<
beans:property
name
=
"defaultFailureUrl"
value
=
"/admin/login?error=true"
/>
</
beans:bean
>
<!-- This filter handles a Single Logout Request from the CAS Server -->
<!-- <beans:bean id="myCasFilter" class="org.jasig.cas.client.session.SingleSignOutFilter"></beans:bean> -->
<!-- This filter redirects to the CAS Server to signal Single Logout should
be performed -->
<!-- <beans:bean id="myLogoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter">
<constructor-arg value="https://localhost:9443/cas/logout"/> <constructor-arg>
<bean class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler"/>
</constructor-arg> <property name="filterProcessesUrl" value="/j_spring_cas_security_logout"/>
</beans:bean> -->
<!-- 未登陸用戶跳轉頁面 -->
<
beans:bean
id
=
"authenticationProcessingFilterEntryPoint"
class
=
"org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"
>
<
beans:constructor-arg
value
=
"/admin/login"
/>
</
beans:bean
>
</
beans:beans
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
web-app
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns
=
"http://xmlns.jcp.org/xml/ns/javaee"
xmlns:jsp
=
"http://java.sun.com/xml/ns/javaee/jsp"
xsi:schemaLocation
=
"http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id
=
"WebApp_ID"
version
=
"3.1"
>
<
display-name
>springmvc_food</
display-name
>
<
description
>springmvc_food</
description
>
<
context-param
>
<
param-name
>webAppRootKey</
param-name
>
<
param-value
>app.root.food</
param-value
>
</
context-param
>
<
context-param
>
<
param-name
>privateKey</
param-name
>
<
param-value
>MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAmbcvGVNGREmiuQPehURivFsMFwanlqAr8PGzdMSQMW1bPHd8jfGUkSQMey0G7BH3rFZjQITBt1NICN2wVznBAwIDAQABAj80PQzEjohSrLOgLLBymcr0N/zj1l8d0VEdkQZrqGFYakkh5FbLBS/wveLuLBTwoeNDEh8D680psFgCq0XDVeECIQDnr5LM8vo6UjwjsjESOjwYVJDzIZwseepeJDFMvrP4EQIhAKnY4Fsy66PsuVafncJXdUakZiZN3VokbU7S+wE4kpvTAiB9rCoIC+CZlBPVFQozJe2FERITH+8T3Qm5CQ7I30TF0QIgKcg6WPUL1sWTSmX1rytIpFoo7t9UxqoTYcKxELnUBxUCIQC3mJSmwP6dXijCy10aiBm/b4pfpdveA5dj4yegZnLYPw==</
param-value
>
<
description
></
description
>
</
context-param
>
<
context-param
>
<
param-name
>publicKey</
param-name
>
<
param-value
>MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJm3LxlTRkRJorkD3oVEYrxbDBcGp5agK/Dxs3TEkDFtWzx3fI3xlJEkDHstBuwR96xWY0CEwbdTSAjdsFc5wQMCAwEAAQ==</
param-value
>
<
description
></
description
>
</
context-param
>
<
context-param
>
<
param-name
>contextConfigLocation</
param-name
>
<
param-value
>
classpath:beans.xml,
classpath:spring-security.xml
</
param-value
>
</
context-param
>
<!-- spring 整合索賠日內個mvc的時候是否須要寫ContextLoaderListener -->
<
listener
>
<
listener-class
>org.springframework.web.context.ContextLoaderListener</
listener-class
>
</
listener
>
<
filter
>
<
filter-name
>characterEncodingFilter</
filter-name
>
<
filter-class
>org.springframework.web.filter.CharacterEncodingFilter</
filter-class
>
<
init-param
>
<
param-name
>encoding</
param-name
>
<
param-value
>UTF-8</
param-value
>
</
init-param
>
<
init-param
>
<
param-name
>ForceEncoding</
param-name
>
<
param-value
>true</
param-value
>
</
init-param
>
</
filter
>
<
filter-mapping
>
<
filter-name
>characterEncodingFilter</
filter-name
>
<
url-pattern
>/*</
url-pattern
>
</
filter-mapping
>
<!-- 登陸驗證權限 -->
<
filter
>
<
filter-name
>springSecurityFilterChain</
filter-name
>
<
filter-class
>org.springframework.web.filter.DelegatingFilterProxy</
filter-class
>
</
filter
>
<
filter-mapping
>
<
filter-name
>springSecurityFilterChain</
filter-name
>
<
url-pattern
>/*</
url-pattern
>
</
filter-mapping
>
<!--配置 HiddenHttpMethodFilter請能夠把post請求轉爲delete請求或者post請求改爲put -->
<
filter
>
<
filter-name
>hiddenHttpMethodfilter</
filter-name
>
<
filter-class
>org.springframework.web.filter.HiddenHttpMethodFilter</
filter-class
>
</
filter
>
<
filter-mapping
>
<
filter-name
>hiddenHttpMethodfilter</
filter-name
>
<
url-pattern
>/*</
url-pattern
>
</
filter-mapping
>
<!-- sitemesh 配置 -->
<
filter
>
<
filter-name
>sitemesh</
filter-name
>
<
filter-class
>com.sniper.springmvc.sitemesh3.MySiteMeshFilter</
filter-class
>
</
filter
>
<
filter-mapping
>
<
filter-name
>sitemesh</
filter-name
>
<
url-pattern
>/*</
url-pattern
>
</
filter-mapping
>
<!-- springmvc 配置 -->
<
servlet
>
<
servlet-name
>springDispatcherServlet</
servlet-name
>
<
servlet-class
>org.springframework.web.servlet.DispatcherServlet</
servlet-class
>
<
init-param
>
<
param-name
>contextConfigLocation</
param-name
>
<
param-value
>classpath:springmvc.xml</
param-value
>
</
init-param
>
<!-- 加載時建立 -->
<
load-on-startup
>1</
load-on-startup
>
</
servlet
>
<
servlet-mapping
>
<
servlet-name
>springDispatcherServlet</
servlet-name
>
<
url-pattern
>/</
url-pattern
>
</
servlet-mapping
>
<
jsp-config
>
<
jsp-property-group
>
<
url-pattern
>*.jsp</
url-pattern
>
<
url-pattern
>*.ftl</
url-pattern
>
<
trim-directive-whitespaces
>true</
trim-directive-whitespaces
>
</
jsp-property-group
>
</
jsp-config
>
</
web-app
>
|