标签: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
原文地址:http://134264.blog.51cto.com/124264/1705475