cai772088996 2016-06-28 15:14 采纳率: 100%
浏览 1237
已采纳

整了一晚上SpringMVC,就是出不来!

为了方便大神们的在线阅读,我把截图贴出来,再为了方便大神们帮我测试,我把代码也贴在截图下面,谢谢!

好了,开始贴截图+代码:

1,控制器

图片说明

@Controller
@RequestMapping("/Hello")
public class HelloWorldController {

@RequestMapping("/a")
public ModelAndView test1(){
    System.out.println("测试一下");
    ModelAndView andView = new ModelAndView();
    andView.addObject("msg", "供视图引用的一段信息");
    andView.setViewName("/WEB-INF/views/Hello.jsp");
    return andView;

2,配置文件

图片说明
<?xml version="1.0" encoding="UTF-8"?>
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.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.cailikun" />

<!-- 开启对spring注解的支持 ,为了低版本兼容(Spring3.2及以上已自带) -->
<context:annotation-config />
<!-- 静态资源访问 -->
<mvc:default-servlet-handler />
<!-- SpringMVC开启注解支持,也是为了低版本兼容 -->
<mvc:annotation-driven />

<!-- 配置上传解析器 -->
<bean id="multipartResolver"
    class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <!-- 设置上传文件的最大尺寸为1MB -->
    <property name="maxUploadSize">
        <value>1048576</value>
    </property>
</bean>

3,web.xml,有点长就不截图了,直接拷代码,抱歉

<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
SpringMVC

<!-- 放置到最前面:处理中文乱码的过滤器 -->
<filter>
    <filter-name>CharacterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <!-- 告诉spring 按照什么编码进行转码 -->
    <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>


<servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    <init-param>
        <!-- 告诉spring配置文件的放置从哪里加载 -->
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:springmvc-servlet.xml</param-value>
    </init-param>

    <!-- 配置了这个后,当服务器启动时,就开始实例化SpringMVC的核心控制器DispatcherServlet(有且只有一次) -->
    <!-- 也就是说:服务器启动变慢,访问变快 -->
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>springmvc</servlet-name>

    <!-- url-pattern常用的两种配置方式: -->
    <!--1, *.do 拦截以do为后缀的请求 -->
    <!--2, / -->
    <url-pattern>/</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>

4,jsp视图

图片说明

求拯救!实在不知道怎么办了,检查了下被加载到tomcat里的文件,发现了一些疑问,怀疑也可能是tomcat的问题,这个链接就是后续提问:http://ask.csdn.net/questions/266317

  • 写回答

3条回答 默认 最新

  • cai772088996 2016-06-28 15:25
    关注

    好了,我日了天狗了,整了这么久,一个clean,没事了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。