我试图将datatype int的 studentId传递给servlet,但它不接受它并强制将数据类型更改为String
int studentId;
String studentName;
studentId = request.getParameter("StudentId"); // (cannot convert from int to String).
Run Code Online (Sandbox Code Playgroud)
我无法将其更改为String,因为在数据库中,studentId是一个整数(主键),我的java类也将int作为参数.
我怎么解决这个问题?
如何使用jstl获取/设置复选框值并仅删除选中复选框的数据库中的那些记录?您是否还可以建议如何在jstl中使用三元运算符?
SearchStudent.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Lookup Students</title>
</head>
<form method="post" action="deleteStudentServlet" class="form">
<body class="body">
<!-- List results -->
<c:if test="${not empty studentList}">
<table border="1" cellspacing="0" cellpadding="0" :>
<tr>
<th></th>
<th>ID</th>
<th>Title</th>
<th>First Name</th>
<th>Last Name</th>
<th></th>
</tr>
<c:forEach var="students" items="${studentList}">
<tr>
<td><input type="checkbox" name="chkBox"> </td>
<td>${students.studentID}</td>
<td>${students.title}</td>
<td>${students.firstName}</td>
<td>${students.lastName}</td>
<td><c:url value="UDS" var="url">
<c:param name="StudentID" value="${students.studentID}" />
</c:url> <a href="${url}">Edit</a></td>
</tr>
</c:forEach>
</table>
</c:if>
<td><input …Run Code Online (Sandbox Code Playgroud) 我已经在application.propertiesSpring Boot 应用程序的文件中配置了休眠属性。
应用程序属性
#hibernate config
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.datasource.url=<db_url>
spring.datasource.username=<username>
spring.datasource.password=<password>
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
# Show or not log for each sql query
spring.jpa.show-sql = true
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# ThymeLeaf
spring.thymeleaf.cache= false
spring.thymeleaf.mode=LEGACYHTML5
Run Code Online (Sandbox Code Playgroud)
当我尝试获取会话时出现错误
Configuration configuration = new Configuration();
configuration.configure("application.properties");
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build());
Session session = sessionFactory.openSession();
Run Code Online (Sandbox Code Playgroud)
错误:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.hibernate.HibernateException:
Could not parse configuration: application.properties] …Run Code Online (Sandbox Code Playgroud) 我试图使用ResultSetHandler将学生列表传递给servlet,但得到以下错误
java.lang.NumberFormatException: For input string: "id"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
Run Code Online (Sandbox Code Playgroud)
Student类中的方法是
public List<Student> list2() throws SQLException {
Connection connection = null;
List<Student> studentList = null;
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)
envCtx.lookup("jdbc/TestDB");
connection = ds.getConnection();
ResultSetHandler h = new ArrayListHandler();
QueryRunner run = new QueryRunner(ds);
String sql = "select student_id, student_name from tbl_student";
studentList = (List<Student>)run.query(sql, h);
}catch(SQLException sqle) {
sqle.printStackTrace();
}
catch(Exception e) {
e.printStackTrace();
}
finally {
DbUtils.closeQuietly(connection);
}
return …Run Code Online (Sandbox Code Playgroud)