springmvc乱码疑惑

有如下代码:在点击URL方式的时候name参数的中文在后台可以正确显示,但是在浏览器直接输入中文的时候为什么后台就是乱码了[code="java"]<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



index

<a href="${pageContext.request.contextPath}/user/welcome?name=哈哈">URL方式</a>

<form action="${pageContext.request.contextPath}/user/login" method="post">
    <span>用户名</span><input type="text" name="username" /><br/>
    <span>密&nbsp;&nbsp;&nbsp;&nbsp;码</span><input type="password" name="password" /><br/>
    <input type="submit" value="登录" />
</form>


[/code]
Controller:[code="java"] @RequestMapping(value = "/welcome",method = RequestMethod.GET)
public String welcome(ModelMap model,HttpServletRequest request){

    String name = request.getParameter("name");

    System.out.println("*********"+name+"*************");

    model.put("name", name);

    System.out.println("*********welcome*************");

    return "welcome";

}[/code]web.xml[code="java"]<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright : adobocode.com , 2010 -->

xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="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/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
id="WebApp_ID" version="2.4">
springmvc

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


<servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

[/code]

查看全部
lxm_yl
ascendlin
2011/09/30 13:00
  • it技术
  • 互联网问答
  • IT行业问题
  • 编程语言问答
  • 计算机技术
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

0个回复