单数据提交
//Index.jsp
单个数据提交
i d:
姓名:
//servlet类
@Controller
public class DataSubmitAction {
/**
*i d:
*姓名:
*/
@RequestMapping(value = "/one")
public String oneData(int id,String name){
System.out.println("id:"+id+" name:"+name);
return "main";
}
}
对象数据提交
POJO
Index.jsp
对象数据提交
i d:
姓名:
Servlet类(controller)
@RequestMapping(value = "/Object")
public String ObjectData(User user){
System.out.println(" id:"+user.getId()+" name:"+user.getName());
return "main";
}
动态占位符数据提交
用于超链接或地址栏提交数据
Index.jsp
动态占位符提交数据
Servlet类(controller)
@RequestMapping(value = "/placeholder/{id}/{name}")
public String placeholderData(@PathVariable int id,@PathVariable String name){
System.out.println("id: "+id+" name:"+name);
return "main";
}
或者
请求参数名称映射数据提交
解决映射名称不一致问题(提交请求参数的action的形参名称不一致,使用@RequestParam注解解析)
Index.jsp
请求参数名称映射提交数据
i d:
姓名:
Servlet类(controller)
@RequestMapping("/Mapping")
public String MappingData(@RequestParam("id") int myid,@RequestParam("name") String myname){
System.out.println("id:"+myid+" name:"+myname);
return "main";
}
Servlet手工提取数据
Index.jsp
Servlet手工提取数据
i d:
姓名:
Servlet类(controller)
@RequestMapping("/handwork")
public String handworkData(HttpServletRequest request){
String id = request.getParameter("id");
String name = request.getParameter("name");
System.out.println("id:"+id+" name:"+name);
return "main";