码迷,mamicode.com
首页 > 编程语言 > 详细

Spring mvc环境搭建

时间:2015-10-23 16:41:29      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:spring mvc

第一步,讲相关包拷贝到lib文件加下

第二步配置 WEB.CONFIG

        

<?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_3_0.xsd" id="WebApp_ID" version="3.0">

 <filter> 
      <filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
 </filter-mapping> 
  <servlet>

    <servlet-name>dispatcherServlet</servlet-name>

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

    <load-on-startup>1</load-on-startup>

  </servlet>

  <servlet-mapping>

    <servlet-name>dispatcherServlet</servlet-name>

    <url-pattern>/</url-pattern>

  </servlet-mapping>
 
    

</web-app>

第三步 配置springMVC配置文件   <servlet-name>-Servlet.xml

 


    <!-- 自动扫描的包名 -->

    <context:component-scan base-package="com.Ace.controller"></context:component-scan>

    <!-- 默认的注解映射的支持 -->

    <mvc:annotation-driven />

    <!-- 视图解释类 -->

    <bean

        class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="prefix" value="/WEB-INF/Views/" />

        <!--可为空,方便实现自已的依据扩展名来选择视图解释类的逻辑 -->

        <property name="suffix" value=".jsp" />

    </bean>

第四部

   创建index.jsp页面,

   <form action="hello" method="post" >
    你好:<input type="text" id="name" name="name"></input>
    <input type="submit" value="提交"></input>
    </form>

 

   hello.jsp

   <div>${username}</div>

第五部创建后台JAVA文件hello.java

  

//hello world

        @RequestMapping(value="/hello")
        public String hello(@RequestParam("name") String name,Map<String ,String> context) throws UnsupportedEncodingException{
         //String name1 =  name.toString("file.encoding","utf-8");
         String encoding = System.getProperty("file.encoding"); 
           
          // name=java.net.URLDecoder.decode(name,"");
           System.out.println("系统默认的字符集是:" + name+encoding);
          //  System.out.println(name.Encoding("utf-8")); 
           context.put("username", name);
            return "hello";

        }

Spring mvc环境搭建

标签:spring mvc

原文地址:http://134264.blog.51cto.com/124264/1705475

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!