码迷,mamicode.com
首页 > 其他好文 > 详细

Property 'username' has no setter method in class

时间:2016-05-29 19:51:39      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html>
  <head>
    <title>带数据给RequestDemo02</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <form action="/firstWebProject/servlet/RequestDemo02" method="post">
    	用户名1:<input type="text" name="username" ><br />
    	用户名2:<input type="text" name="username" ><br />
    	密码:<input type="password" name="password" ><br />
    	<input type="submit" value="提交">
    </form>
  </body>
</html>

  

package cn.hfy;
import ....
// 获取请求数据(一般都要先检查再使用) public class RequestDemo02 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //Map map = request.getParameterMap(); Map<String, String[]> map = request.getParameterMap(); User1 user = new User1(); // 内部原理:根据key和value的类型,通过反射赋值 try { BeanUtils.populate(user, map); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(user); // 此处打个断点,服务器debug方式启动查看user } } class User1 { private String username[]; // 为了掩饰多个值用一个key。所以此处使用数组。 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; } }

运行,出现以下错误:Property ‘username‘ has no setter method in class ‘class cn.hfy.User‘

刚出现,很疑惑。随即反应过来, User1并不是public的。

The class must be public, and provide a public constructor that accepts no arguments. This allows tools and applications to dynamically create new instances of your bean, without necessarily knowing what Java class name will be used ahead of time。

明白了错误,原来如此的,嗯......

Property 'username' has no setter method in class

标签:

原文地址:http://www.cnblogs.com/hfy82/p/5540027.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!