什么都还来的及

报错信息及解决方法

1.eclipse使用maven,启动工程tomcat报错:java.lang.ClassNotFoundException: org.springframework.web.context.Contex

  原因:tomcat 中没有相关的jar,但是工作空间是有这些jar 的;

  已解决:https://blog.csdn.net/java_mr_zheng/article/details/50166167   

  项目 —> 属性 -> Deployment Assembly -> Add -> Java Build Path Entries -> 选择Maven Dependencies(或者全部的jar包) -> Finish -> OK

 2.cannot change version of project facet Dynamic Web Module to 3.0

 已解决:https://blog.csdn.net/dm1314oooooooo/article/details/70859189

 

 方法:找到 \项目名\.setting\文件夹下的 org.eclipse.wst.common.project.facet.core.xml xml文件

 修改为:

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <fixed facet="wst.jsdt.web"/>
  <installed facet="jst.web" version="3.0"/>
  <installed facet="wst.jsdt.web" version="1.0"/>
  <installed facet="java" version="1.7"/>
</faceted-project>

  update 即可。

 3. tomcat启动时错误:Failed to start component [StandardEngine[Catalina].StandardHost[localhost].错误

  先将项目从tomcat 中移除,在将tomcat 移除,在重新添加tomcat和项目就好了~

4. spring @ResponseBody 返回 JSON 乱码

  <!-- 处理请求返回json字符串的中文乱码问题 -->
    <mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

  在添加 </mvc:annotation-driven> 标签后报错:cvc-complex-type.2.1: Element 'mvc:annotation-driven' must have no character or element information

  解决方法:https://blog.csdn.net/id19870510/article/details/53861407

  原因是:http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 中不包含这个标签 需要替换 成                 http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd    或在Controller

@RequestMapping(value  = "/user", produces = "text/html; charset=utf-8")   //添加返回的 context-type 和 编码
	@ResponseBody
	public String selectAllUser() {
		List<Useraccount> list = userService.selectUser();
		JSONArray jsArr = new JSONArray();
		JSONObject jsonObject  = null ;
		for (Useraccount useraccount : list) {
			jsonObject = new JSONObject();
			jsonObject.put("Uid", useraccount.getUid());
			jsonObject.put("UserName", useraccount.getUsername());
			jsonObject.put("Nickname", useraccount.getNickname());
			jsonObject.put("Password", useraccount.getPassword());
			jsArr.add(jsonObject);
		}
		
		return jsArr.toString();
	}

  

posted @ 2018-05-19 08:16  coder_sun  阅读(289)  评论(0编辑  收藏  举报