【发布时间】:2014-07-24 23:27:50
【问题描述】:
我有 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);
%>
下面是构造函数的代码 公共类用户 { 私人字符串用户名; 私人字符串电子邮件地址; 私人字符串密码; 私有字符串注释; 私人字符串电子邮件格式; 私有字符串 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;
}
你能帮我解决这个问题吗?如果您需要更多详细信息,请告诉我
【问题讨论】: