我的Java webapp中存在问题.
这是index.jsp中的代码:
<%@page contentType="text/html" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<% request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<form action="index.jsp" method="get">
<input type="text" name="q"/>
</form>
Res: <%= request.getParameter("q") %>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我发送请求时,我的浏览器发送此标头:
GET /kjd/index.jsp?q=%C3%A9 HTTP/1.1\r\n
...
Accept-Charset: UTF-8,*\r\n
Run Code Online (Sandbox Code Playgroud)
Tomcat服务器将此返回给我:
Content-Type: text/html;charset=UTF-8\r\n
Run Code Online (Sandbox Code Playgroud)
但是如果我在表单中发送"é"(在UTF-8中为%C3%A9),则会显示"é".
我的理解是浏览器发送一个用UTF-8(%C3%A9)编码的"é".
但是服务器将其解释为ISO-8859-1.所以%C3被解码为Ã而%A9被解码为©,然后发回以UTF-8编码的响应.
在代码中,请求应使用UTF-8解码:
request.setCharacterEncoding("UTF-8");
Run Code Online (Sandbox Code Playgroud)
但是,如果我发送此网址:
http://localhost:8080/kjd/index.jsp?q=%E9
Run Code Online (Sandbox Code Playgroud)
"%E9"用ISO-8859-1表示,显示"é".
为什么这不起作用?为什么请求使用ISO-8859-1进行解码?
我在Tomcat 6和7以及Windows和Ubuntu上尝试过它.
我在测试类上使用Spring Boot的方便注释,用于集成测试.
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Config.class)
@IntegrationTest
@Sql({"classpath:rollback.sql", "classpath:create-tables.sql"})
@Transactional
Run Code Online (Sandbox Code Playgroud)
我发现在每个测试类上复制/粘贴整个块非常难看,所以我创建了自己的@MyIntegrationTest注释
@SpringApplicationConfiguration(classes = Config.class)
@IntegrationTest
@Sql({"classpath:database-scripts/rollback.sql", "classpath:database-scripts/create-tables.sql", "classpath:database-scripts/insert-test-data.sql"})
@Transactional
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(value = RetentionPolicy.RUNTIME)
@interface MyIntegrationTest {
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我@RunWith(SpringJUnit4ClassRunner.class)在我的新注释中添加,那么JUnit将使用其默认运行符运行 - 这是不可取的.所以现在我必须使用两个注释.
@RunWith(SpringJUnit4ClassRunner.class)
@MyIntegrationTest
Run Code Online (Sandbox Code Playgroud)
我想现在好了,但是有没有办法结合这些注释,所以我可以使用单个注释?
我在 IntelliJ 中使用了 ajc 编译器,以及 aspectj-maven-plugin,我在其中声明了以下排除项:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>**/EmployeeAccessAspect.java</exclude>
</excludes>
<complianceLevel>1.8</complianceLevel>
<showWeaveInfo>true</showWeaveInfo>
<verbose>true</verbose>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
当我使用 编译时mvn compile,一切都很好,并且EmployeeAccessAspect方面被正确忽略。
但是,如果我Make是 IntelliJ 中的项目,它只会编织它找到的所有方面(并完全忽略 maven 排除项)。
我总是可以破解 ajc 编译器选项或方面路径来实现我想要的,但是如果我出于某种原因必须排除一个方面,它会让我改变两个地方。
有什么办法可以让maven插件和ajc编译同步吗?我正在使用 IntelliJ 15。
为什么 Haskell 不能在Num类型上执行模式匹配,而不需要我们指定Eq为类型类?
例如:
h :: Num a => a -> a
h 0 = -1
h x = x + 1
Run Code Online (Sandbox Code Playgroud)
编译这个函数时,ghci抱怨:
* Could not deduce (Eq a) arising from the literal `0'
from the context: Num a
bound by the type signature for:
h :: forall a. Num a => a -> a
at functions.hs:9:1-20
Possible fix:
add (Eq a) to the context of
the type signature for:
h :: forall a. …Run Code Online (Sandbox Code Playgroud) java ×3
annotations ×1
aspectj ×1
haskell ×1
jsp ×1
junit ×1
maven ×1
servlets ×1
spring-boot ×1
tomcat ×1