发表于: 2017-12-11 21:35:31
1 689
今天完成的事情:
我要跟大家分享几个灰常牛逼(2B)的BUG,我这一天基本就是排BUG,不过通过排BUG,意识到了几个问题.
①BUG NUM1
我在使用XML注解方式写的MVC小项目部署到tomcat上没有问题,只要改为使用annotation(注解)的方式就会出500异常, 显示没法读取配置文件等一系列的各种问题.
500
java.lang.IncompatibleClassChangeError: class org.springframework.cglib.core.DebuggingCla
如果遇到这个异常,一定是第三方的jar包冲突了,导致tomcat不知道使用哪个包.
我是因为在任务一的时候看了一篇教程,那个教程可能有点久远了,他所要求的jar包中包含了ASM这个jar包.
其实在最新的Spring-core JAR包中已经默认包含了.
解决方案:
②BUG NUM2
写好的小项目在本地tomcat下能够运行, 放到linux服务器上就不行了,这里主要也是因为一个路径的问题.
<%--
Created by IntelliJ IDEA.
User: 52840
Date: 2017/12/11
Time: 17:10
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<fieldset>
<legend>用户注册</legend>
<form action="${pageContext.request.contextPath}/ssm/param" >
姓名:<input type="text" name="name" id="name"/>
年龄:<input type="text" name="age" id="age"/>
生日:<input type="text" name="birthday" id="birthday"/>
地址:<input type="text" name="address" id="address"/>
<input type="submit" value="提交"/>
</form>
</fieldset>
</body>
</html>
在action href 这一系列来表示我们的映射方法的时候,需要加上
${pageContext.request.contextPath}
在我们本地的时候不加这个运行也毫无问题
参考资料:http://blog.csdn.net/qq_25821067/article/details/53131847
代码部分:
Controller
package com.controller;
import com.bean.Student;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
/**
* @author Arike
* Create_at 2017/12/11 11:40
*/
@Controller
@RequestMapping("/ssm")
public class MyController {
Logger logger = Logger.getLogger(MyController.class);
@RequestMapping("/hello")
public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
ModelAndView mv = new ModelAndView();
mv.setViewName("add");
return mv;
}
@RequestMapping("/param")
public ModelAndView method1(String name, Integer age, Date birthday,String address)throws Exception{
ModelAndView mv = new ModelAndView();
Student student = new Student(name, age, birthday, address);
logger.info(student);
mv.setViewName("index");
return mv;
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<filter>
<filter-name>characterEncoding</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>characterEncoding</filter-name>
<url-pattern>/</url-pattern>
</filter-mapping>
<!--配置前端分配器-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 如果要使用默认加载方式,满足以下2个条件:
默认加载必须规范:
* 文件命名:servlet-name-servlet.xml====springmvc.xml
* 路径规范:必须在WEB-INF目录下面
就可以不用写<init-param></init-param>
-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<!--服务器启动就一起初始化,数值越小,优先级越高
服务器启动的时候就加载bean类
-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/jsps/index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Springmvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!--配置组件扫描路径-->
<context:component-scan base-package="com"/>
<!--开启注解驱动支持
配置处理器映射器寻找Controller
配置处理器适配器执行Controller
-->
<mvc:annotation-driven/>
<!--静态资源的处理-->
<mvc:default-servlet-handler/>
<!-- 配置sprigmvc视图解析器:解析逻辑试图
后台返回逻辑试图:index
视图解析器解析出真正物理视图:前缀+逻辑试图+后缀====/WEB-INF/jsps/index.jsp
-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!--前缀-->
<property name="prefix" value="/jsps/"/>
<!--后缀-->
<property name="suffix" value=".jsp"/>
</bean>
</beans>
项目欢迎(进入)页面.
index.jsp
<%--
Created by IntelliJ IDEA.
User: Yong
Date: 2017/12/1
Time: 16:13
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>XX论坛欢迎你</title>
</head>
<body>
<a href="${pageContext.request.contextPath}/ssm/hello">
<img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=273041809,4048522111&fm=27&gp=0.jpg">
</a>
</body>
</html>
这里我做的是一个图片点击跳转链接,
添加页面
add.jsp
<%--
Created by IntelliJ IDEA.
User: 52840
Date: 2017/12/11
Time: 17:10
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<fieldset>
<legend>用户注册</legend>
<form action="${pageContext.request.contextPath}/ssm/param" >
姓名:<input type="text" name="name" id="name"/>
年龄:<input type="text" name="age" id="age"/>
生日:<input type="text" name="birthday" id="birthday"/>
地址:<input type="text" name="address" id="address"/>
<input type="submit" value="提交"/>
</form>
</fieldset>
</body>
</html>
明天计划的事情:
使用Rest风格完成任务一的service.
遇到的问题:
各种BUG..
收获:
页面好玩.....
评论