1.今天在做一个例子的时候,发现后台不能正确接收中文的url参数,试了各种解决办法都不可以。
以下是代码:
Controller:
package com.springapp.mvc;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/")
public class HelloController {
@RequestMapping(method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
model.addAttribute("message", "Hello world IDEA!");
model.put("content","This is my first springmvc web");
return "index";
}
@RequestMapping(value = "/page/{name}/{age}",method = RequestMethod.GET)
public String getName(ModelMap modelMap, @PathVariable("name") String name, @PathVariable("age") int age) {
modelMap.addAttribute("name",name);
modelMap.addAttribute("age",age);
return "name";
}
}
name.jsp
名字:${name}
年龄:${age}
web.xml
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">
Spring MVC Application
mvc-dispatcher
org.springframework.web.servlet.DispatcherServlet
1
mvc-dispatcher
/
characterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
characterEncodingFilter
/*