Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
d0f13b5b
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d0f13b5b
编写于
8月 25, 2010
作者:
A
Arjen Poutsma
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SPR-7490 - Reverting RedirectView to it's 3.0.3 version
上级
4504ab8b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
35 addition
and
34 deletion
+35
-34
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/RedirectView.java
...va/org/springframework/web/servlet/view/RedirectView.java
+35
-34
未找到文件。
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/RedirectView.java
浏览文件 @
d0f13b5b
...
...
@@ -19,6 +19,7 @@ package org.springframework.web.servlet.view;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.lang.reflect.Array
;
import
java.net.URLEncoder
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collections
;
...
...
@@ -32,7 +33,6 @@ import org.springframework.beans.BeanUtils;
import
org.springframework.http.HttpStatus
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.web.servlet.View
;
import
org.springframework.web.util.UriUtils
;
import
org.springframework.web.util.WebUtils
;
/**
...
...
@@ -207,36 +207,27 @@ public class RedirectView extends AbstractUrlBasedView {
Map
<
String
,
Object
>
model
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
String
encoding
=
getEncoding
(
request
);
// Prepare target URL.
StringBuilder
targetUrl
=
new
StringBuilder
();
if
(
this
.
contextRelative
&&
getUrl
().
startsWith
(
"/"
))
{
// Do not apply context path to relative URLs.
targetUrl
.
append
(
UriUtils
.
encodePath
(
request
.
getContextPath
(),
encoding
));
targetUrl
.
append
(
UriUtils
.
encodeUri
(
getUrl
(),
encoding
));
}
else
{
targetUrl
.
append
(
UriUtils
.
encodeUri
(
getUrl
(),
encoding
));
targetUrl
.
append
(
request
.
getContextPath
());
}
targetUrl
.
append
(
getUrl
());
if
(
this
.
exposeModelAttributes
)
{
appendQueryProperties
(
targetUrl
,
model
,
encoding
);
String
enc
=
this
.
encodingScheme
;
if
(
enc
==
null
)
{
enc
=
request
.
getCharacterEncoding
();
}
if
(
enc
==
null
)
{
enc
=
WebUtils
.
DEFAULT_CHARACTER_ENCODING
;
}
appendQueryProperties
(
targetUrl
,
model
,
enc
);
}
sendRedirect
(
request
,
response
,
targetUrl
.
toString
(),
this
.
http10Compatible
);
}
private
String
getEncoding
(
HttpServletRequest
request
)
{
String
enc
=
this
.
encodingScheme
;
if
(
enc
==
null
)
{
enc
=
request
.
getCharacterEncoding
();
}
if
(
enc
==
null
)
{
enc
=
WebUtils
.
DEFAULT_CHARACTER_ENCODING
;
}
return
enc
;
}
/**
* Append query properties to the redirect URL.
* Stringifies, URL-encodes and formats model attributes as query properties.
...
...
@@ -261,7 +252,7 @@ public class RedirectView extends AbstractUrlBasedView {
boolean
first
=
(
getUrl
().
indexOf
(
'?'
)
<
0
);
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
queryProperties
(
model
).
entrySet
())
{
Object
rawValue
=
entry
.
getValue
();
Iterator
valueIter
;
Iterator
valueIter
=
null
;
if
(
rawValue
!=
null
&&
rawValue
.
getClass
().
isArray
())
{
valueIter
=
Arrays
.
asList
(
ObjectUtils
.
toObjectArray
(
rawValue
)).
iterator
();
}
...
...
@@ -280,8 +271,8 @@ public class RedirectView extends AbstractUrlBasedView {
else
{
targetUrl
.
append
(
'&'
);
}
String
encodedKey
=
UriUtils
.
encodeQueryParam
(
entry
.
getKey
(),
encodingScheme
);
String
encodedValue
=
(
value
!=
null
?
UriUtils
.
encodeQueryParam
(
value
.
toString
(),
encodingScheme
)
:
""
);
String
encodedKey
=
urlEncode
(
entry
.
getKey
(),
encodingScheme
);
String
encodedValue
=
(
value
!=
null
?
urlEncode
(
value
.
toString
(),
encodingScheme
)
:
""
);
targetUrl
.
append
(
encodedKey
).
append
(
'='
).
append
(
encodedValue
);
}
}
...
...
@@ -289,7 +280,7 @@ public class RedirectView extends AbstractUrlBasedView {
// Append anchor fragment, if any, to end of URL.
if
(
fragment
!=
null
)
{
targetUrl
.
append
(
fragment
);
}
}
}
/**
...
...
@@ -372,6 +363,20 @@ public class RedirectView extends AbstractUrlBasedView {
return
(
value
!=
null
&&
BeanUtils
.
isSimpleValueType
(
value
.
getClass
()));
}
/**
* URL-encode the given input String with the given encoding scheme.
* <p>The default implementation uses <code>URLEncoder.encode(input, enc)</code>.
* @param input the unencoded input String
* @param encodingScheme the encoding scheme
* @return the encoded output String
* @throws UnsupportedEncodingException if thrown by the JDK URLEncoder
* @see java.net.URLEncoder#encode(String, String)
* @see java.net.URLEncoder#encode(String)
*/
protected
String
urlEncode
(
String
input
,
String
encodingScheme
)
throws
UnsupportedEncodingException
{
return
(
input
!=
null
?
URLEncoder
.
encode
(
input
,
encodingScheme
)
:
null
);
}
/**
* Send a redirect back to the HTTP client
* @param request current HTTP request (allows for reacting to request method)
...
...
@@ -398,18 +403,14 @@ public class RedirectView extends AbstractUrlBasedView {
/**
* Determines the status code to use for HTTP 1.1 compatible requests.
* <p>The default implemenetation returns the {@link #setStatusCode(HttpStatus) statusCode}
* property if set, or the value of the {@link #RESPONSE_STATUS_ATTRIBUTE} attribute.
*
If neither are
set, it defaults to {@link HttpStatus#SEE_OTHER} (303).
* property if set, or the value of the {@link #RESPONSE_STATUS_ATTRIBUTE} attribute.
If neither are
* set, it defaults to {@link HttpStatus#SEE_OTHER} (303).
* @param request the request to inspect
* @param response the servlet response
* @param targetUrl the target URL
* @return the response status
* @return the response
*/
protected
HttpStatus
getHttp11StatusCode
(
HttpServletRequest
request
,
HttpServletResponse
response
,
String
targetUrl
)
{
if
(
this
.
statusCode
!=
null
)
{
return
this
.
statusCode
;
protected
HttpStatus
getHttp11StatusCode
(
HttpServletRequest
request
,
HttpServletResponse
response
,
String
targetUrl
)
{
if
(
statusCode
!=
null
)
{
return
statusCode
;
}
HttpStatus
attributeStatusCode
=
(
HttpStatus
)
request
.
getAttribute
(
View
.
RESPONSE_STATUS_ATTRIBUTE
);
if
(
attributeStatusCode
!=
null
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录