Home > Back-end >  Registration information input to mysql but appeared Unable to compile class for JSP:
Registration information input to mysql but appeared Unable to compile class for JSP:

Time:09-25

HTTP Status 500 - Unable to compile class for JSP:

Type Exception report

The message Unable to compile class for JSP:

Description The server encountered an internal error that prevented it from fulfilling this request.

The exception

Org. Apache. Jasper. JasperException: Unable to compile class for JSP:

An error occurred at line: 19 in the JSP file:/Doregister JSP
The method setAge (Integer) in The type User is not applicable for The arguments (String)
16: User u=new User ();
17: u.s etName (name);
18: u.s etPass (pass);
19: u.s etAge (age);
20: UserDao udao=new UserDao ();
21://call the method that udao implementation into function
22: int x=udao. Insert (u);


Stacktrace:
Org.apache.jasper.com piler. DefaultErrorHandler. JavacError (DefaultErrorHandler. Java: 92)
Org.apache.jasper.com piler. ErrorDispatcher. JavacError (ErrorDispatcher. Java: 330)
Org.apache.jasper.com piler. JDTCompiler. GenerateClass (JDTCompiler. Java: 460)
Org.apache.jasper.compiler.Compiler.com running (356) Compiler. Java:
Org.apache.jasper.compiler.Compiler.com running (334) Compiler. Java:
Org.apache.jasper.compiler.Compiler.com running (321) Compiler. Java:
Org.apache.jasper.JspCompilationContext.com from running (JspCompilationContext. Java: 592)
Org. Apache. Jasper. Servlet. JspServletWrapper. Service (328) JspServletWrapper. Java:
Org. Apache. Jasper. Servlet. JspServlet. ServiceJspFile (JspServlet. Java: 321)
Org. Apache. Jasper. Servlet. JspServlet. Service (267) JspServlet. Java:
Javax.mail. Servlet. HTTP. HttpServlet. Service (HttpServlet. Java: 723)


Note The full stack trace of The root cause is available in The Apache Tomcat/6.0.53 logs.


Doregister. JSP:

<% @ page import="com. Tao. The entity. The User" % & gt;
<% @ page language="Java" contentType="text/HTML. Charset=utf-8 "
PageEncoding="utf-8" % & gt;


<meta HTTP - equiv="content-type" Content="text/HTML. Charset=utf-8 "& gt;
Insert title here

<body>
<%//to get name password, and age
String name=request. The getParameter (" username ");
String pass=request. The getParameter (" password ");
String age=request. The getParameter (" age ");
The User u=new User ();
U.s etName (name);
U.s etPass (pass);
U.s etAge (age);
UserDao udao=new UserDao ();
//call the method that udao implementation into function
Int x=udao. Insert (u);
If (x>=1) {
//forwarding, if & gt; 1, jump to success2. The JSP page
Request. GetRequestDispatcher ("/Success. JSP "). The forward (request, response);
}
% & gt;



BaseDao:

Package com. Tao. Dao;

Import the Java. SQL. Connection;
Import the Java. SQL. DriverManager;
Import of Java, SQL PreparedStatement;
Import the Java. SQL. The ResultSet;
Import Java, SQL Statement;

Public class BaseDao {
Protected Connection conn=null;
Protected the Statement STMT=null;
Protected the ResultSet rs=null;
Protected String url="JDBC: mysql://localhost: 3306/student3? CharacterEncoding=utf-8 ";
Protected String name="root";
Protected String password="123456";
Protected PreparedStatement PSTMT=null;

Public void the connect () {
Try {
Class.forName("com.mysql.jdbc.Driver");
Conn=DriverManager. GetConnection (url, "root", "123456");
STMT=conn. CreateStatement ();
} the catch (Exception e) {
e.printStackTrace();
}
}

Public void closeAll () {
Try {
if (rs !=null) {
rs.close();
}
If (STMT!=null) {
STMT. Close ();
}
If (conn!=null) {
conn.close();
}
If (PSTMT!=null) {
PSTMT. Close ();
}
} the catch (Exception e) {

}
}
}

UserDao. Java
Package com. Tao. Dao;

The import com. Tao. The entity. The User;

Public class UserDao extends BaseDao {
Public User the dologin (String name, String pass) {
The User u=null;
Try {
Super. The connect ();
String SQL="select * from the user where name=? And pass=?" ;
PSTMT=conn. PrepareStatement (SQL);
PSTMT. SetString (1, name);
PSTMT. SetString (2, pass);
Rs=PSTMT. ExecuteQuery ();
While (rs), next ()) {
U=new User ();
U.s etId (rs. Get int (1));
U.s etName (rs. Get string (2));
U.s etPass (rs. Get string (3));
U.s etAge (rs. Get string (4));
}
} the catch (Exception e) {
e.printStackTrace();
} the finally {
Super. CloseAll ();
}
The return of u;
}
Public int insert User (u) {
Int row=0;
Try {
Super. The connect ();
String SQL="insert into user (name, pass, age) values (?,?,?,?,? ,? ,?) ";
PSTMT=conn. PrepareStatement (SQL);
PSTMT. SetString (1, u.g etName ());
PSTMT. SetString (2, u.g etPass ());
PSTMT. SetString (3, u.g etAge ());
The row=PSTMT. ExecuteUpdate ();
} the catch (Exception e) {
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related