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 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛