67,512
社区成员
发帖
与我相关
我的任务
分享
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8" import="com.medto.entity.User"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<form action="./WHK/logs" method="post">
user<input type="text" name="username">
password<input type="password" name="password">
<input type="submit" value="log">
</form>
</body>
</html>
package com.medto.entity;
public class User {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "User [username=" + username + ", password=" + password + "]";
}
public User(String username, String password) {
super();
this.username = username;
this.password = password;
}
}
package com.medto.controller;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.medto.entity.User;
@Controller
@RequestMapping("/WHK")
public class DispatcherController {
//从页面获取数据模型
@RequestMapping(value="/logs",method=RequestMethod.POST)
public String logs(@ModelAttribute("user")User user){
User user1=new User(user.getUsername(), user.getPassword());
System.out.println("进来了");
System.out.println(user1.getUsername());
return "show";
}
}
[/quote]你的那个是无参数构造器吗?要不就加个无参数构造器,要不就把你的构造器去掉就可以了[/quote]
嗯嗯 你说的对 好了, 能告诉我下为什么需要这样吗package com.medto.controller;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.medto.entity.User;
@Controller
@RequestMapping("/WHK")
public class DispatcherController {
//从页面获取数据模型
@RequestMapping(value="/logs",method=RequestMethod.POST)
public String logs(@ModelAttribute("user")User user){
User user1=new User(user.getUsername(), user.getPassword());
System.out.println("进来了");
System.out.println(user1.getUsername());
return "show";
}
}
[/quote]你的那个是无参数构造器吗?要不就加个无参数构造器,要不就把你的构造器去掉就可以了package com.medto.controller;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.medto.entity.User;
@Controller
@RequestMapping("/WHK")
public class DispatcherController {
//从页面获取数据模型
@RequestMapping(value="/logs",method=RequestMethod.POST)
public String logs(@ModelAttribute("user")User user){
User user1=new User(user.getUsername(), user.getPassword());
System.out.println("进来了");
System.out.println(user1.getUsername());
return "show";
}
}