25.1 新建一个UserController类
package com.ask.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.ask.controller.entity.User;
//添加地址;
@RequestMapping("/user")
@Controller
public class UserController{
@RequestMapping(value="/add")
public String getUser(@RequestParam(value="username") String username,
@RequestParam(value="password") String password,
@RequestParam(value="age") int age,
@RequestParam(value="sex") String sex){
System.out.println("username "+username+" password"+password+" age"+age+" sex"+sex);
return "user_list";
}
}
25.2 新建一个springmvc-servlet.xml的配置文件,用来解析最后要输出的jsp网页
"1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
25.3 新建一个user_list.jsp文件
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
"Content-Type" content="text/html; charset=utf-8">
用户添加成功
25.4 在web.xml配置文件中配置如下:
"1.0" encoding="UTF-8"?>
25.5 新建一个index.jsp文件
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
"Content-Type" content="text/html; charset=utf-8">