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

j2ee之springMVC中的web.xml一个简单调用

时间:2017-09-10 18:59:02      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:调用   中文   rac   jsp   new   pre   col   add   bsp   

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" 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">

    <!-- 注册springmvc核心控制器 -->
    <servlet>
        <servlet-name>DispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- 通知DispatcherServlet去指定的目录下加载springmvc.xml配置文件 -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>DispatcherServlet</servlet-name>
        <url-pattern>*.action</url-pattern>
    </servlet-mapping>

    <!-- 注册spring提供的针对POST请求的中文乱码问题 -->
    <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>
    <display-name>Archetype Created Web Application</display-name>
</web-app>

 

package com.newtouch.action;

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

@Controller
@RequestMapping("/user")
public class FirstMVC {
    @RequestMapping("/hello")//可以通过{“”,“”,“”}添加多个
    public String hello(Model model) {
        model.addAttribute("msg", "你成功了");
        return "/index.jsp";
    }
}

 

j2ee之springMVC中的web.xml一个简单调用

标签:调用   中文   rac   jsp   new   pre   col   add   bsp   

原文地址:http://www.cnblogs.com/ShaoXin/p/7501663.html

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