小编Muh*_*mad的帖子

将int作为参数从JSP传递给servlet

我试图将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作为参数.

我怎么解决这个问题?

jsp servlets

7
推荐指数
1
解决办法
8万
查看次数

如何在JSP中检查复选框

如何使用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)

checkbox jsp jstl

7
推荐指数
1
解决办法
4万
查看次数

Spring Boot 应用程序中的 application.properties 与 hibernate.cfg.xml

我已经在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)

hibernate spring-boot

6
推荐指数
1
解决办法
3万
查看次数

DBUtils - 使用ResultSetHandler

我试图使用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)

java jsp servlets jdbc

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

jsp ×3

servlets ×2

checkbox ×1

hibernate ×1

java ×1

jdbc ×1

jstl ×1

spring-boot ×1