问答详情
源自:4-8 接收参数-深入Struts2

接收参数的时候出现了异常

http://img.mukewang.com/59bfe2810001273008520365.jpg

http://img.mukewang.com/59bfe2820001bdfe12750489.jpg

个别代码:

(login.jsp)

<form action="LoginAction.action" method="post">

    用户名:<input type="text" name="username"/>

    密码:<input type="password" name="password"/>

    书籍1:<input type="text" name="bookList[0]"/>

  书籍2:<input type="text" name="bookList[1]"/>

  <input type="submit" value="提交"/>

    </form>

(LoginAction.java)

private UserMessage user = new UserMessage();

public String login(){

System.out.println(user.getUsername());

System.out.println(user.getBookList().get(0));

System.out.println(user.getBookList().get(1));

//..............

return SUCCESS;

}


@Override

public UserMessage getModel() {

// TODO Auto-generated method stub

return user;

}

(UserMessage.java)

public class UserMessage {

private String username;

private String password;

private List<String> bookList ;

public UserMessage() {

super();

}

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;

}

public List<String> getBookList() {

return bookList;

}

public void setBookLsit(List<String> bookList) {

this.bookList = bookList;

}

}

开发工具用的是Myeclipse10。做了很多的尝试,最后发现将UserMessage中的bookList实例化就不会报错了?可以为什么呢?老师的不用实例化?

提问者:益达佳帅 2017-09-18 23:19

个回答

  • 慕粉3228645
    2017-09-20 13:20:24

    set方法里就是实例化啊