A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© REVEBAMBOU 初级黑马   /  2019-6-5 19:41  /  386 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

In this week, I learned spring, spring-mvc, mybatis, and so on. Some issues were encountered, Here is the list:
1. [maven] A child container failed during start (This is not the root caused)
Description:
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/reve]]
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/reve]]
Caused by: java.lang.ClassCastException: org.springframework.web.SpringServletContainerInitializer cannot be cast to javax.servlet.ServletContainerInitializer (root caused)
Reason:
This is caused by jar package
1. existed jar package:
spring-webmvc 5.0.5, javax.servlet.jsp-api 2.2.1, javax.servlet-api 3.0.1, tomcat 7, and
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
Solution: remove javax.servlet-api 3.0.1
2. [maven] Skipping non-war project
maven tomcat7 can be booted, but the server is unable to be used, and tip "Skipping non-war project" is presented in the console.
Reason:
Missing mark <packaging>war<packaging> in the pom.xml
3. [tomcat7] Messy issues
Request: (both get and post methods)
1. Set VM Options: -Dfile.encoding=gbk or gb2312 (This make sure the console will displayed normally.) and another place is add mark <uriEncoding>UTF-8</uriEncoding> in the configuration of tomcat7-maven-plugin
Response:(both get and post methods)
1. Use produces="text/plain;charset=utf-8" is RequestMapping
2. Use mvc:annotation-driven:
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="defaultCharset" value="utf-8"></property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
Post method in request:
<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>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Extra method:
URLEncoder.encode
URLDecoder.decode

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马