Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wxlzmt committed Jul 13, 2018
1 parent cf86c4d commit f508d56
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/main/java/com/ect/imp/web/CharacterEncodingFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
public class CharacterEncodingFilter implements javax.servlet.Filter {

private String defaultEncoding = "UTF-8";
/**释义:是否过滤POST请求的参数.*/
/**释义:是否过滤POST请求的参数.*/
private boolean enableFilterPostMethod = true;
/**释义:是否过滤GET请求的参数.*/
/**释义:是否过滤GET请求的参数.*/
private boolean enableFilterGetMethod = true;

@Override
Expand All @@ -31,8 +31,9 @@ public void destroy() {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
// 处理请求乱码
if (enableFilterPostMethod || enableFilterGetMethod) {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
String method = httpServletRequest.getMethod();
if ((method.equalsIgnoreCase("POST") && enableFilterPostMethod) || (method.equalsIgnoreCase("GET") && enableFilterGetMethod)) {
HttpServletRequest myRequest = new MyRequest(httpServletRequest);
filterChain.doFilter(myRequest, response);
} else {
Expand Down Expand Up @@ -89,15 +90,15 @@ public Map getParameterMap() {
}
// 先获得请求方式
String method = request.getMethod();
if (method.equalsIgnoreCase("POST") && enableFilterPostMethod) { // post方式请求
if (method.equalsIgnoreCase("POST")) { // post方式请求
try {
request.setCharacterEncoding(defaultEncoding);
this.cachedParameterMap = request.getParameterMap();
return this.cachedParameterMap;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} else if (method.equalsIgnoreCase("GET") && enableFilterGetMethod) { // get方式请求
} else if (method.equalsIgnoreCase("GET")) { // get方式请求
Map<String, String[]> parameterMap = request.getParameterMap();
if (!hasEncode) {
for (String parameterName : parameterMap.keySet()) {
Expand Down
3 changes: 0 additions & 3 deletions src/main/webapp/check.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,10 @@ hr {
<tr><td>remotePort</td><td><%=request.getRemotePort() %></td></tr>
<tr><td>remoteUser</td><td><%=request.getRemoteUser() %></td></tr>
<tr><td>authType</td><td><%=request.getAuthType() %></td></tr>
<tr><td>isAsyncStarted</td><td><%=request.isAsyncStarted() %></td></tr>
<tr><td>isAsyncSupported</td><td><%=request.isAsyncSupported() %></td></tr>
<tr><td>isRequestedSessionIdFromCookie</td><td><%=request.isRequestedSessionIdFromCookie() %></td></tr>
<tr><td>isRequestedSessionIdFromURL</td><td><%=request.isRequestedSessionIdFromURL() %></td></tr>
<tr><td>isRequestedSessionIdValid</td><td><%=request.isRequestedSessionIdValid() %></td></tr>
<tr><td>isSecure</td><td><%=request.isSecure() %></td></tr>
<tr><td>isTrailerFieldsReady</td><td><%=request.isTrailerFieldsReady() %></td></tr>
<tr><td>toString</td><td><%=request.toString() %></td></tr>
</table>
</div>
Expand Down

0 comments on commit f508d56

Please sign in to comment.