zoukankan      html  css  js  c++  java
  • springmvc搭建

    1.web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" 
        xmlns="http://java.sun.com/xml/ns/javaee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
      <servlet>
          <servlet-name>kongzhi</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>kongzhi</servlet-name>
           <url-pattern>/</url-pattern>
      </servlet-mapping>
      
    </web-app>
    2.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"
        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.2.xsd">
     
        <context:component-scan base-package="com.cai" />
          <!-- 配置视图解析器 -->
    
       <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    
          <property name="suffix" value=".jsp"/> <!-- 视图后缀,controller中的方法返回的url字符串会添加该后缀 -->
    
          <property name="prefix" value="/WEB-INF/views/"/> <!-- 视图后缀controller中的方法返回的url字符串会添加该前缀 -->
    
       </bean>
      </beans>
    3.jar包
    commons-logging-1.1.1.jar
    spring-aop-4.0.3.RELEASE.jar
    spring-beans-4.0.3.RELEASE.jar
    spring-context-4.0.3.RELEASE.jar
    spring-core-4.0.3.RELEASE.jar
    spring-expression-4.0.3.RELEASE.jar
    spring-web-4.0.3.RELEASE.jar
    spring-webmvc-4.0.3.RELEASE.jar

    4.Java类

    package com.cai;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Controller
    public class SayHello {
        @RequestMapping("/hello")
        public String helloString () {
            System.out.println("caidachun的第一个程序");
            return "success";
            
        }
    }

    5.视图页面和success.jsp

     <body>
       <a href="hello">This is my JSP page.</a><br>
      </body>
     <body>
        我的jsp页面 <br>
      </body>

    6.截图

  • 相关阅读:
    HDU --1251
    POJ -- 2436
    POJ -- 3140
    POJ 3107
    POJ -- 2002
    POJ -- 1655
    lintcode154
    lintcode192
    lintcode582
    lintcode901
  • 原文地址:https://www.cnblogs.com/caidachun-didi/p/13738545.html
Copyright © 2011-2022 走看看