发表于: 2017-08-14 22:29:18

1 993


今天完成的事:

今天想重新整合一次springmvc,然后像师兄那样, 需要什么的东西的时候在去陪什么. 需要哪些依赖在去加相关需要的依赖,复习和巩固这次的功能,但是也不是那么顺利的. 404一直缠绕着我,一个简单的springmvc都不能配的出来.  

在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:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
   <mvc:annotation-driven />
   <mvc:default-servlet-handler/>
                      <!--配置自动扫描包-->
         <context:component-scan base-package="com.jnshu.controller"/>

                   <!--配置视图解析器-->
     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
         <property name="prefix" value="/WEB-INF/views/"></property>
         <property name="suffix" value=".jsp"></property>
     </bean>

</beans>


web.xml中只配置容器的加载和

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
        xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

                        <!--配置servlet-->
  <servlet>
    <servlet-name>springDispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:springmvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

   <servlet-mapping>
       <servlet-name>springDispatcherServlet</servlet-name>
       <url-pattern>/</url-pattern>
   </servlet-mapping>
</web-app>



controller中配置一个根据hellowrld这个url打印两句话,去到成功页面,



我直接输入localhost:8080 是报404的,这个时候加上项目名,也是报的404,我的记得这个是maven差价你的jetty启动的, 师兄是说要加项目名,这个时候,我在看看success的jsp,他是不需要的加项目名就可以进入到success页面的.



我成功页面可以进入,至少那个主页要要能出来的,硬是出不来. 在确保我项目比较干净的情况下.这次我就去看看之前的项目怎么出来的,看到了之前的任务2的项目index页面在webapp下与web-INF同级,我也就是是看这个新的项目webapp目录,发现index 在WEB-INF之下与viesw文件夹同级,有点奇怪,我这次把index啦到webapp之下,在试试,重新启动. 好了



结果,修改一下index页面进入,对于这个跳转的问题,我的controller写的是根据holleworld 这个url跳转到success,

所以在href标签这里如果直接写jsp的名字是跳转不了的. 这里一直会错意了,之前师兄说的我理解成,直接写jsp页面的名字就可以实现跳转         jsp页面标签的这个helloworld对应的是controller写的url地址

@RequestMapping("/helloworld")




最后在controller中,我发现进入不了这个index页面还特意为这个index页面写了个contrller呢,这个貌似不需要啊

package com.jnshu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
* Created by PC on 2017/8/14.
*/
@Controller
public class HelloWorld {
@RequestMapping("/helloworld")
public String hello(){
System.out.println("hello world" );
          System.out.println("是打发是发达的速度方式都萨芬的是发达" );
          return "success";
      }

@RequestMapping("/index")
public String hello2(){
return "index";
      }
}

明天的计划:springmvc与tiles整合起来添加图片







遇到的问题:重新整合的springmvc的404,不是特别的理解这个路径 与在index中跳转









收获:自己又复习了一次springmvc,对springmvc更加深刻,然后利用之前的项目与师兄教的办法,终于自己成功解决了这些问题,














进度: 任务4

         


返回列表 返回列表
评论

    分享到