JSP项目中的构造函数不确定

发布于 2025-01-25 15:05:42 字数 1927 浏览 2 评论 0原文

我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过去的过去 2025-02-01 15:05:42

这似乎很粗糙,但是,您是否尝试将构造函数的返回分配给变量?
登录登录=新登录(电子邮件,密码,userrole);

It may seem crude, but, have you tried assigning the constructor's return to a variable?
Login login = new Login(email, password, userRole);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文