springmvc代码详细(五种映射,绑定参数,处理json数据,文件上传,转发,拦截器的实现)
程序员文章站
2022-07-09 21:10:45
...
项目结构图:
父工程的pom.xml文件:
<!-- 集中定义依赖版本号 -->
<properties>
<junit.version>4.10</junit.version>
<spring.version>4.1.3.RELEASE</spring.version>
<mybatis.version>3.2.8</mybatis.version>
<mybatis.spring.version>1.2.2</mybatis.spring.version>
<mybatis.paginator.version>1.2.15</mybatis.paginator.version>
<mysql.version>5.1.32</mysql.version>
<slf4j.version>1.6.4</slf4j.version>
<jackson.version>2.4.2</jackson.version>
<druid.version>1.0.9</druid.version>
<httpclient.version>4.3.5</httpclient.version>
<jstl.version>1.2</jstl.version>
<servlet-api.version>2.5</servlet-api.version>
<jsp-api.version>2.0</jsp-api.version>
<joda-time.version>2.5</joda-time.version>
<commons-lang3.version>3.3.2</commons-lang3.version>
<commons-io.version>1.3.2</commons-io.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- 单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- Spring Springmvc-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis.spring.version}</version>
</dependency>
<dependency>
<groupId>com.github.miemiedev</groupId>
<artifactId>mybatis-paginator</artifactId>
<version>${mybatis.paginator.version}</version>
</dependency>
<!-- MySql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!--日志-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- Jackson Json处理工具包 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- 连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<!-- httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<!-- JSP相关 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp-api.version}</version>
<scope>provided</scope>
</dependency>
<!-- 时间操作组件 -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
<!-- Apache工具组件 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- 资源文件拷贝插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- java编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!-- 配置Tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
子工程的pom.xml文件:
<dependencies>
<!--日志-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<!--spring mvc-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<!-- Jackson Json处理工具包 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- JSP相关 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<!--上传-->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 资源文件拷贝插件 -->
<!-- 配置Tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8080</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
springmvc-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!--配置请求分发的 handlermapping-->
<!--<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean>
-->
<!--配置适配器-->
<!--<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></bean>-->
<!--开启扫描包 寻找注解功能-->
<!--访问时 会自动寻找包下含有controller注解的类-->
<context:component-scan base-package="com.ljh.web"/>
<!--配置注解驱动-->
<mvc:annotation-driven/>
<!--配置具体的handler 其实就是类路径-->
<!-- <bean name="/hello.do" class="com.ljh.web.hello" ></bean>-->
<!--配置视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"></property><!--表示前缀 寻找试图的路径-->
<property name="suffix" value=".jsp"></property><!--表示后缀 为.jsp的文件-->
</bean>
<!-- 定义文件上传解析器 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 设定默认编码 -->
<property name="defaultEncoding" value="UTF-8"></property>
<!-- 设定文件上传的最大值5MB,5*1024*1024 ,指的是所有文件的总和 -->
<property name="maxUploadSize" value="5242880"></property>
</bean>
<!--配置拦截器-->
<mvc:interceptors>
<mvc:interceptor>
<!--定义所有请求都进入拦截器-->
<mvc:mapping path="/**"/>
<!--指定是哪个拦截器-->
<bean class="com.ljh.web.MyHandler"></bean>
</mvc:interceptor>
<!--可以配置多个拦截器 比如-->
<!--<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean class="com.ljh.web.MyHandler2"></bean>
</mvc:interceptor>-->
</mvc:interceptors>
</bean
web.xml:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<!--配置过滤器 解决乱码问题-->
<filter>
<!--注意这里是filter,不要配置成servlet-->
<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><!--URL映射,给所有页面处理乱码-->
</filter-mapping>
<!--配置核心控制器 servlet-name就是springmvc-servlet.xml配置文件的名字,-后面的名字是固定的 前面的可以随意取-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--加载springmvc-servlet.xml配置文件-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<!-- <url-pattern>*.do</url-pattern>-->
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
User:
package com.ljh.pojo;
public class User {
private Integer id;
private String name;
private Integer age;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
'}';
}
}
Hello2:
package com.ljh.web;
import com.ljh.pojo.ListUser;
import com.ljh.pojo.User;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@Controller
public class Hello2 {
/**
* 五种映射方式的演示 从show1到show7
* @return
*/
//标椎url映射
@RequestMapping("show1")
public ModelAndView test1(){
ModelAndView mv = new ModelAndView();
mv.addObject("msg","第一个注解程序");
mv.setViewName("hello");
return mv;
}
//ant方式映射 *代表通配符 有* 和** 两种方式 一个*只能匹配一个位置的字符 两个* 可以匹配0个,一个或者多个位置的字符
//比如:/*/show2 URL可以写成 /aaa/show2.do ;/**/show2 url可以写成 /show2.do 或者 /aa/show2.do 以及/aa/bb/show2.do 都可以
@RequestMapping("/**/show2")
public ModelAndView test2(){
ModelAndView mv = new ModelAndView("hello");
mv.addObject("msg","这是通配符映射");
return mv;
}
//占位符映射 其中{userid}和{username}就是两个占位符 在URL中这两个位置可以写任意字符
//@PathVariable() 可以通过这个注解来获取占位符的值
@RequestMapping("test/{userid}/{username}/show3")
public ModelAndView test3(@PathVariable("userid") int id,@PathVariable("username")String name){
ModelAndView mv = new ModelAndView("hello");
mv.addObject("msg","这是占位符映射 userid:"+id+"username:"+name);
return mv;
}
//限制请求方式映射 可以写多种请求方式 用{}就可以 如果一个的话 就不需要{}了 405:请求方式错误
@RequestMapping(value = "show4",method = {RequestMethod.GET,RequestMethod.POST})
public ModelAndView test4(){
ModelAndView mv = new ModelAndView("hello");
mv.addObject("msg","这是限制请求方式映射");
return mv;
}
//限制请求参数
@RequestMapping(value = "show5",params = "userId") //表示url必须要带上UuserId这个参数才可以访问 比如/shoiw5.do?userId=任意值
public ModelAndView test5(){
ModelAndView mv = new ModelAndView("hello");
mv.addObject("msg","这是限制请求方式映射");
return mv;
}
@RequestMapping(value = "show6",params = "!userId") //表示url中UuserId不能作为参数的名称才可以访问 比如/shoiw5.do?aaa=任意值
public ModelAndView test6(){
ModelAndView mv = new ModelAndView("hello");
mv.addObject("msg","这是限制请求方式映射");
return mv;
}
@RequestMapping(value = "show7",params = "userId!=1") //表示url中UuserId的值不能等于1才可以访问 比如/shoiw5.do?userId=除了1以外都可以
public ModelAndView test7(){
ModelAndView mv = new ModelAndView("hello");
mv.addObject("msg","这是限制请求方式映射");
return mv;
}
//如何获取页面上的请求参数 获取form表单的数据
@RequestMapping("show8")
public void test8(HttpServletRequest request, HttpServletResponse response){
String username = request.getParameter("userName");
String password = request.getParameter("passWord");
System.out.println(username+" "+password);
}
//第二种获取请求参数的方式 @RequestParam() 相当于request.getParameter()
//@RequestParam()里面还有两个属性 required和defaultValue
//required默认为true 表示该属性必须要赋值 如果是false的话 该属性可以不赋值就提交表单 如果是int类型的属性设置为false的话 会出现400错误 最好使用Ingeter类型 因为int类型不写会用0表示 0也是数字
//defaultValue是默认值的意思 如果有defaultValue的话 那么required就会失效
@RequestMapping("show9")
public ModelAndView test9(@RequestParam("username" ) String username,@RequestParam("age") int age ){
ModelAndView mv = new ModelAndView("hello");
mv.addObject("msg","username="+username+"age="+age);
return mv;
}
//获取cookie的值
@RequestMapping("show11") //通过这种方法进去到cookie.jsp页面 通过视图解析器解析返回的字符串 实现跳转页面
public String test11(){
return "cookie";
}
@RequestMapping("show10") //从cookie.jsp页面跳转到 show10中
public String test10(@CookieValue(value = "name",required = false) String name,@CookieValue(value = "age") int age){
System.out.println(name+" "+age);
return "hello";
}
//pojo对象传递参数
@RequestMapping("show12")
public ModelAndView test12(User user){
ModelAndView mv = new ModelAndView("hello");
mv.addObject("msg",user);
System.out.println(user);
return mv;
}
//数据类型的绑定
@RequestMapping("show13")
@ResponseStatus(HttpStatus.OK)//响应状态码 可以解决返回值为void的问题 因为这个注解直接响应了成功的状态码
public void test13(@RequestParam("name") String name,
@RequestParam("age")Integer age,
@RequestParam("income")Double income,
@RequestParam("isMarried")Boolean isMarried,
@RequestParam("interests")String[] interests){
System.out.println("name="+name);
System.out.println("age="+age);
System.out.println("income="+income);
System.out.println("isMarried="+isMarried);
System.out.println("interests="+interests);
}
//list绑定 这里面的方法不能直接用集合做参数 所以创建了一个ListUser类做参数
@RequestMapping("show14")
@ResponseStatus(HttpStatus.OK)
public void test14(ListUser listUser){
if(listUser.getUser()!=null){
for(User u : listUser.getUser()){
System.out.println(u);
}
}
}
//jsp 和jstl视图解析器
@RequestMapping("show15")
public ModelAndView test15(){
ModelAndView mv = new ModelAndView("users");
User user1 = new User();
user1.setId(1);
user1.setName("张三");
user1.setAge(20);
User user2 = new User();
user2.setId(2);
user2.setName("李四");
user2.setAge(20);
User user3 = new User();
user3.setId(3);
user3.setName("王五");
user3.setAge(20);
User user4 = new User();
user4.setId(4);
user4.setName("小明");
user4.setAge(20);
List<User> list = new ArrayList<User>();
list.add(user1);
list.add(user2);
list.add(user3);
list.add(user4);
mv.addObject("list",list);
return mv;
}
//以json格式输出数据 单个对象
@RequestMapping("show16")
@ResponseBody //用@ResponseBody会把返回的对象进行json输出 注意是返回的对象
public User test16(){
User user1 = new User();
user1.setId(1);
user1.setName("张三");
user1.setAge(20);
return user1;
}
//集合处理
@RequestMapping("show17")
@ResponseBody
public List<User> test17(){
User user1 = new User();
user1.setId(1);
user1.setName("张三");
user1.setAge(20);
User user2 = new User();
user2.setId(2);
user2.setName("李四");
user2.setAge(20);
User user3 = new User();
user3.setId(3);
user3.setName("王五");
user3.setAge(20);
User user4 = new User();
user4.setId(4);
user4.setName("小明");
user4.setAge(20);
List<User> list = new ArrayList<User>();
list.add(user1);
list.add(user2);
list.add(user3);
list.add(user4);
return list;
}
//处理json数据并显示出来
@RequestMapping("show18")
@ResponseBody
public List<User> test18(){
User user1 = new User();
user1.setId(1);
user1.setName("张三");
user1.setAge(20);
User user2 = new User();
user2.setId(2);
user2.setName("李四");
user2.setAge(20);
User user3 = new User();
user3.setId(3);
user3.setName("王五");
user3.setAge(20);
List<User> list = new ArrayList<User>();
list.add(user1);
list.add(user2);
list.add(user3);
return list;
}
//跳转json页面方法
@RequestMapping("show19")
public String test19(){
return "json";
}
//接收json串转换为pojo对象
@RequestMapping("show20")
@ResponseStatus(HttpStatus.OK)
public void test20(@RequestBody User user){
System.out.println(user);
}
//集合
@RequestMapping("show21")
@ResponseStatus(HttpStatus.OK)
public void test21(@RequestBody List<User> list){
for(User u : list){
System.out.println(u);
}
}
//通用页面的跳转 也要在核心控制器中修改url路径为/* 原本是*.do
@RequestMapping("{path}")
public String test22(@PathVariable("path") String path){
return path;
}
//文件上传
@RequestMapping("upload.do")
public String upload(@RequestParam("file") MultipartFile multipartFile) throws Exception{
if(multipartFile != null){
multipartFile.transferTo(new File("e://temp//"+multipartFile.getOriginalFilename()));
}
return "success";
}
//转发 forward 不仅可以转发跳转页面 还可以跳转到方法上
@RequestMapping("show22")
public String test22(){
/*return "forward:user.html"; */
return "forward:/rest/show1";
}
@RequestMapping("login")
public String login(){
return "forward:/login.jsp";
}
}
MyHandler拦截器:
package com.ljh.web;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MyHandler implements HandlerInterceptor {
//前置方法
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
System.out.println("执行前置方法");
return true;//true 表示继续执行后面的逻辑 false 表示不继续执行
}
//后置方法
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
System.out.println("执行后置方法");
}
//完成方法
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
System.out.println("执行完成方法");
}
}
cookie.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
<script>
document.cookie="name=zhangsan";
document.cookie="age=20";
</script>
</head>
<body>
<a href="show10.do">提交</a>
</body>
</html>
hello.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%--isELIgnored="false"这句话是添加上去的 因为在页面中原本是不能使用el表达式的 这句话的意思就是忽略el表达式 现在可以使用el表达式来获取数据了--%>
<html>
<head>
<title>Title</title>
</head>
<body>
${msg}
</body>
</html>
json.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
<title>Title</title>
<%--因为本地没有jquery包 所以引入网上的包--%>
<script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$.ajax({
type:"get",
url:"/show18.do",
success: function (data) {
var t = "";
$(data).each(function (i) {
t += "<tr><td>" + data[i].id + "<tr><td>" + data[i].name + "<tr><td>" + data[i].age+"<tr><td>"
});
$("table").append(t);
}
});
</script>
<table border="1">
<tr>
<td>id</td>
<td>name</td>
<td>age</td>
</tr>
</table>
</body>
</html>
success.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
上传成功
</body>
</html>
upload.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h2>上传页面</h2>
<form action="/rest/upload.do" method="post" enctype="multipart/form-data" >
<input type="file" name="file" ><br>
<input type="submit" value="上传">
</form>
</body>
</html>
users.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<table border="1">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<c:forEach items="${list}" var="user">
<tr>
<td>${user.id}</
<td>
<td>${user.name}</
<td>
<td>${user.age}</
<td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>
list.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<form action="/show14.do">
用户1:<input type="text" name="user[0].name"/><br/><%--这个user必须要和ListUser类中的变量名一样 那么要和User中的变量名一样--%>
用户2:<input type="text" name="user[1].name"/><br/>
用户3:<input type="text" name="user[2].name"/><br/>
<input type="submit" value="测试"/>
</form>
</body>
</html>
user.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="/show8.do" method="post">
姓名:<input type="text" name="userName"><br/>
密码:<input type="password" name="passWord"><br/>
<input type="submit">
</form>
<form action="/show13.do" method="post">
<div>姓名:</div>
<div><input name="name" value="张三"/></div>
<div class="clear"></div>
<div>年龄:</div>
<div><input name="age" value="20"/></div>
<div class="clear"></div>
<div>收入:</div>
<div><input name="income" value="100000"/></div>
<div class="clear"></div>
<div>结婚:</div>
<div>
<input type="radio" name="isMarried" value="true" checked="checked"/>是
<input type="radio" name="isMarried" value="false"/>否</div>
<div class="clear"></div>
<div>兴趣:</div>
<div>
<input type="checkbox" name="interests" value="听歌" checked="checked"/>听歌
<input type="checkbox" name="interests" value="书法" checked="checked"/>书法
<input type="checkbox" name="interests" value="看电影" checked="checked"/>看电影
</div>
<div class="clear"></div>
<div><input type="submit" value="提交表单"/></div>
</form>
</body>
</html>
上一篇: SSM的配置过程