JSP - 将String Array传递给构造函数

时间:2014-07-24 23:27:51

标签: jsp checkbox

我有jsp1,用户检查几个复选框 在jsp2上我成功地能够使用String读取复选框值。

但我还需要创建一个用户对象,其中包含在jsp1上选择的参数,以便我可以将其写入文本文件。这就是我遇到路障的地方。当我独立运行时,代码是java控制台,它运行正常。但实际的代码并不是。我收到了以下错误

An error occurred at line: 29 in the jsp file: /ProcessMyForm.jsp
The constructor User(String, String, String, String, String, String[], String) is undefined
26:         String path = sc.getRealPath("/WEB-INF/EmailList.txt");
27: 
28:         // use regular Java objects
29:        User user = new User(userName, emailAddress, password, comment, emailFormat, serverScript, occupation);
30:        UserIO.add(user, path);
31:     %>
32: 

下面是我读取jsp值并尝试创建对象的代码

<%
    // get parameters from the request
    String userName = request.getParameter("userName");
    String emailAddress = request.getParameter("emailAddress");
    String password = request.getParameter("password");
    String comment = request.getParameter("comment");
    String emailFormat = request.getParameter("emailFormat");
    String serverScript[] = request.getParameterValues("serverScript");
    String occupation = request.getParameter("occupation");



    ServletContext sc = this.getServletContext();
    String path = sc.getRealPath("/WEB-INF/EmailList.txt");


   User user = new User(userName, emailAddress, password, comment, emailFormat,  serverScript, occupation);
   UserIO.add(user, path);
%>

以下是构造函数的代码     公共类用户     {     private String userName;     private String emailAddress;     私有字符串密码;     私人字符串评论;     private String emailFormat;     private String serverScript [];     私有字符串占用;

@SuppressWarnings("empty-statement")
public User()
{
    userName = "";
    password = "";
    emailAddress = "";
    comment = "";
    emailFormat = "";
    occupation = "";
}

public User(String userName, String emailAddress, String password, String comment, String emailFormat, String[] serverScript, String occupation)
{
this.userName = userName;
this.emailAddress = emailAddress;
this.password = password;
this.comment = comment;
this.emailFormat = emailFormat;
this.serverScript= serverScript;
this.occupation = occupation;

}

请你帮我解决这个问题。如果您需要更多详细信息,请与我们联系

1 个答案:

答案 0 :(得分:0)

当我关闭并打开Netbeans时,它工作了。我的教授告诉我,有时服务器不会选择更新的课程。