Я пытаюсь применить функцию CRUD в проекте WEB-приложения Dynami c в Eclipse IDE с tomcat v9.0. После ввода я получаю ошибку -
Type: Exception Report
Message: Unable to compile class for JSP:
Description: The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [14] in the generated java file: [C:\Program Files\Apache Software Foundation\Tomcat 9.0\work\Catalina\localhost\Testing4\org\apache\jsp\Controller\insert_005fcontroller_jsp.java]
Only a type can be imported. crud.Insert_Values resolves to a package
An error occurred at line: [20] in the jsp file: [/Controller/insert_controller.jsp]
Insert_Values cannot be resolved to a type
17: String user_name = request.getParameter("user_name");
18:
19:
20: Insert_Values obj_Insert_Values = new Insert_Values();
21: obj_Insert_Values.insert_values(sl_no, user_name, email, mobile);
22:
23:
An error occurred at line: [20] in the jsp file: [/Controller/insert_controller.jsp]
Insert_Values cannot be resolved to a type
17: String user_name = request.getParameter("user_name");
18:
19:
20: Insert_Values obj_Insert_Values = new Insert_Values();
21: obj_Insert_Values.insert_values(sl_no, user_name, email, mobile);
22:
23:
Вот мой java класс:
package crud;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import common.DB_Connection;
public class Insert_Values {
public void insert_values(String sl_no, String user_name, String email, String mobile) {
DB_Connection obj_DB_Connection = new DB_Connection();
Connection connection = obj_DB_Connection.getConnection();
PreparedStatement ps=null;
String query = "insert into user(sl_no, user_name,email,mobile) values(?,?,?)";
try {
ps=connection.prepareStatement(query);
ps.setString(1, sl_no);
ps.setString(2, user_name);
ps.setString(3, email);
ps.setString(4, mobile);
ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Есть мои jsp файлы:
<%@ page import="crud.Insert_Values"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String sl_no = request.getParameter("sl_no");
String email = request.getParameter("email");
String mobile = request.getParameter("mobile");
String user_name = request.getParameter("user_name");
Insert_Values obj_Insert_Values = new Insert_Values();
obj_Insert_Values.insert_values(sl_no, user_name, email, mobile);
%>
Finished
</body>
</html>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Insert Values</h1>
<form action = "Controller/insert_controller.jsp">
Sl No :<input type = "text" name = "sl_no"><br>
User Name :<input type = "text" name = "user_name"><br>
Mobile: <input type ="text" name = "mobile"><br>
Email: <input type = "text" name = "email"><br>
<input type = "submit" value = "Insert">
</form>
</body>
</html>