JSP项目中的构造函数不确定
我在JSP文件中创建一个登录的对象,当我运行此代码时,它会给我错误 无法编译JSP的课程 在第18行中,它显示登录构造函数未定义。 我也导入登录类 我不知道我要去哪里 您能帮我帮助
?
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [18] in the jsp file: [/jsp/login.jsp]
The constructor Login(String, String, String) is undefined
15: String email = request.getParameter("email");
16: String password = request.getParameter("password");
17: String userRole = request.getParameter("desig");
18: new Login(email, password, userRole);
19: out.println("email: "+email);
20: out.println("password: "+password);
21: out.println("userRole: "+userRole);
吗
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import = "com.classes.Login"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Login.jsp</title>
</head>
<body>
<%
// fetching the data from login form
String email = request.getParameter("email");
String password = request.getParameter("password");
String userRole = request.getParameter("desig");
new Login(email, password, userRole);
out.println("email: "+email);
out.println("password: "+password);
out.println("userRole: "+userRole);
%>
</body>
</html>
我
package com.classes;
public class Login {
String email;
String password;
String userRole;
public Login(String email,String password,String userRole) {
this.email = email;
this.password = password;
this.userRole = userRole;
showData();
new Database();
}
public void showData() {
System.out.println("email: "+this.email);
System.out.println("password: "+this.password);
System.out.println("userRole: "+this.userRole);
}
}
I create a object of Login in JSP file and when I run this code it is giving me error
that unable to compile class for JSP
and on line 18 it shows Login constructor is undefined.
I also import the Login class
I don't know where I am going wrong
Can you please help me in this one please
Error I get:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [18] in the jsp file: [/jsp/login.jsp]
The constructor Login(String, String, String) is undefined
15: String email = request.getParameter("email");
16: String password = request.getParameter("password");
17: String userRole = request.getParameter("desig");
18: new Login(email, password, userRole);
19: out.println("email: "+email);
20: out.println("password: "+password);
21: out.println("userRole: "+userRole);
Login.jsp file
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import = "com.classes.Login"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Login.jsp</title>
</head>
<body>
<%
// fetching the data from login form
String email = request.getParameter("email");
String password = request.getParameter("password");
String userRole = request.getParameter("desig");
new Login(email, password, userRole);
out.println("email: "+email);
out.println("password: "+password);
out.println("userRole: "+userRole);
%>
</body>
</html>
Login.java File
package com.classes;
public class Login {
String email;
String password;
String userRole;
public Login(String email,String password,String userRole) {
this.email = email;
this.password = password;
this.userRole = userRole;
showData();
new Database();
}
public void showData() {
System.out.println("email: "+this.email);
System.out.println("password: "+this.password);
System.out.println("userRole: "+this.userRole);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎很粗糙,但是,您是否尝试将构造函数的返回分配给变量?
登录登录=新登录(电子邮件,密码,userrole);
It may seem crude, but, have you tried assigning the constructor's return to a variable?
Login login = new Login(email, password, userRole);