# Conflicts: # .idea/artifacts/gdms_war_exploded.xml # GDMS.imlhechu1
commit
255db387e1
@ -1,17 +0,0 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="exploded-war" name="gdms:Web exploded">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/gdms_Web_exploded</output-path>
|
||||
<root id="root">
|
||||
<element id="javaee-facet-resources" facet="GDMS/web/Web" />
|
||||
<element id="directory" name="WEB-INF">
|
||||
<element id="directory" name="classes">
|
||||
<element id="module-output" name="gdms" />
|
||||
</element>
|
||||
<element id="directory" name="lib">
|
||||
<element id="file-copy" path="C:/Program Files/Apache Software Foundation/Tomcat 8.5/lib/tomcat-jdbc.jar" />
|
||||
<element id="library" level="project" name="lib" />
|
||||
</element>
|
||||
</element>
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
@ -1,4 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
||||
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
|
||||
<file url="file://$PROJECT_DIR$/web/jsFile/login.js" charset="UTF-8" />
|
||||
<file url="PROJECT" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
@ -1,6 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES5" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_10" default="false" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,105 @@
|
||||
package filter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.annotation.WebFilter;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@WebFilter(urlPatterns = "/*")
|
||||
public class CharSet implements Filter {
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
public void doFilter(ServletRequest req, ServletResponse resp,
|
||||
FilterChain chain) throws ServletException, IOException {
|
||||
HttpServletRequest httpServletRequest = (HttpServletRequest) req;
|
||||
// 对request包装增强
|
||||
HttpServletRequest myrequest = new MyRequest(httpServletRequest);
|
||||
((HttpServletResponse)resp).setContentType("text/html;charset=utf-8");
|
||||
chain.doFilter(myrequest, resp);
|
||||
|
||||
}
|
||||
|
||||
public void init(FilterConfig config) throws ServletException {
|
||||
|
||||
}
|
||||
}
|
||||
class MyRequest extends HttpServletRequestWrapper {
|
||||
|
||||
private HttpServletRequest request;
|
||||
|
||||
private boolean hasEncode;
|
||||
|
||||
public MyRequest(HttpServletRequest request) {
|
||||
super(request);
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
// 对需要增强方法 进行覆盖
|
||||
@Override
|
||||
public Map<String, String[]> getParameterMap() {
|
||||
// 先获得请求方式
|
||||
String method = request.getMethod();
|
||||
if (method.equalsIgnoreCase("post")) {
|
||||
// post请求
|
||||
try {
|
||||
// 处理post乱码
|
||||
request.setCharacterEncoding("utf-8");
|
||||
return request.getParameterMap();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (method.equalsIgnoreCase("get")) {
|
||||
// get请求
|
||||
Map<String, String[]> parameterMap = request.getParameterMap();
|
||||
if (!hasEncode) { // 确保get手动编码逻辑只运行一次
|
||||
for (String parameterName : parameterMap.keySet()) {
|
||||
String[] values = parameterMap.get(parameterName);
|
||||
if (values != null) {
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
try {
|
||||
// 处理get乱码
|
||||
values[i] = new String(values[i].getBytes("ISO-8859-1"), "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
hasEncode = true;
|
||||
}
|
||||
return parameterMap;
|
||||
}
|
||||
|
||||
return super.getParameterMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParameter(String name) {
|
||||
Map<String, String[]> parameterMap = getParameterMap();
|
||||
String[] values = parameterMap.get(name);
|
||||
if (values == null) {
|
||||
return null;
|
||||
}
|
||||
return values[0]; // 取回参数的第一个值
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getParameterValues(String name) {
|
||||
Map<String, String[]> parameterMap = getParameterMap();
|
||||
String[] values = parameterMap.get(name);
|
||||
return values;
|
||||
}
|
||||
|
||||
}
|
||||
|
Before Width: | Height: | Size: 650 KiB After Width: | Height: | Size: 816 KiB |
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 2.8 KiB |
@ -1 +0,0 @@
|
||||
|
Loading…
Reference in new issue