Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
数据库中的java jsp文件更新表字段_Java_Sqlite_Jsp_Jakarta Ee - Fatal编程技术网

数据库中的java jsp文件更新表字段

数据库中的java jsp文件更新表字段,java,sqlite,jsp,jakarta-ee,Java,Sqlite,Jsp,Jakarta Ee,我正在尝试更新员工完成的旅行次数在下表中,我得到了员工列表和每个人完成的旅行次数,以及更新该数字的输入字段。但是,我得到错误500 null 有人能帮我解决这个问题吗?非常感谢 内部Controller.java public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { ....

我正在尝试更新员工完成的旅行次数
在下表中,我得到了员工列表和每个人完成的旅行次数,以及更新该数字的输入字段。但是,我得到
错误500 null

有人能帮我解决这个问题吗?非常感谢

内部Controller.java

        public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

    ....

            } else if (methode.equals("post") && action.equals("/updateemployees")) {
                doUpdateEmployee(request, response);
    ....


        private void doUpdateEmployee(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


                int tripsInitialvalue = Integer.valueOf(request.getParameter("nbTrips"));
[line: 177]     int id = Integer.valueOf(request.getParameter("id"));


                EmployeeDAO.addTrips(id,tripsInitialvalue);


                doEmployees(request, response);

            }
public static Employee addTrips(int id, int tripsToAdd) {
        EntityManager em = GestionFactory.factory.createEntityManager();
        Employee employee = em.find(Employee.class, id);
        em.getTransaction().begin();
        int tripsInitialvalue = employee.getNbTrips();
        employee.setNbTrips(tripsInitialvalue + tripsToAdd);
        em.getTransaction().commit();
        em.close();
        return employee;
    }
在myEmployeeDAO.java中

        public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

    ....

            } else if (methode.equals("post") && action.equals("/updateemployees")) {
                doUpdateEmployee(request, response);
    ....


        private void doUpdateEmployee(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


                int tripsInitialvalue = Integer.valueOf(request.getParameter("nbTrips"));
[line: 177]     int id = Integer.valueOf(request.getParameter("id"));


                EmployeeDAO.addTrips(id,tripsInitialvalue);


                doEmployees(request, response);

            }
public static Employee addTrips(int id, int tripsToAdd) {
        EntityManager em = GestionFactory.factory.createEntityManager();
        Employee employee = em.find(Employee.class, id);
        em.getTransaction().begin();
        int tripsInitialvalue = employee.getNbTrips();
        employee.setNbTrips(tripsInitialvalue + tripsToAdd);
        em.getTransaction().commit();
        em.close();
        return employee;
    }
和我的employees.jsp文件:

<form method="post" action="<%= getServletContext().getContextPath()%>/do/updateemployees">  
<table>
    <tr>
        <th>Employee ID</th>
        <th>Name</th>
        <th>Number of Trips</th>        
        <th>Edit Trips</th>
    <tr>
<% for (Employee employee : employees) {%>
    <tr>
        <td><%=employee.getId()%></td>
        <td><%=employee.getName()%></td>        
        <td><%=employee.getNbTrips()%></td>     
        <td><input type="number" name="nbTrips" size="2" value="<%=employee.getNbTrips()%>"></td>
    </tr>
<% } %>
</table>
<input type="submit" value="Update"/>
</form>

因此,从错误详细信息可以明显看出,valueOf正在试图解析代码中的null。您无法将“null”解析为int

编辑: 要获取所有文本框的值,请使用request.getParameterValues('nbTrips'),这将返回具有相同'nbTrips'的元素的所有值

String[] nbTrips = request.getPrameterValues('nbTrips')

将所有名为“nbTrips”的文本框值返回到字符串数组nbTrips中,您可以迭代并从文本框中获取每个值。

发布错误堆栈跟踪和相关代码行。@SasiKathimanda请查看更新的问题,在控制器中添加错误日志和行号。谢谢您的建议,以前的错误已经消失了。但当我更改数字并单击update时,该值不会得到更新,因为它会跳转到else部分,而不会发生任何事情。我应该如何更新该字段?如果它跳到else表示它仍然为空,请进行调试并查看在req.getParameter处得到的值问题是我不知道如何将员工的
id
与表单中的新行程号一起传递给控制器,因为它需要两个参数id和新的跳闸值。你能帮我把表格写好吗?谢谢,但当我添加此id代码时,它只更新列表中的第一个id代码。我有所有员工的列表,输入字段对所有员工都是可编辑的,所以我想为所有员工添加新值,并立即更新所有员工。