servlets – How to fix an exception occurred processing [WEB-INF/user-list.jsp] at line [32] in eclipse

I use tomcat server 9 in eclipse. When run on the server I can get the output of user-list.jsp but when I input the data into the user list.jsp page I got this TTP Status 500 – Internal Server Error. I don’t understand how to fix this error. Can someone please help me to solve this?

When I run this program I’m getting errors like below

HTTP Status 500 – Internal Server Error


Type Exception Report

Message An exception occurred processing [WEB-INF/user-list.jsp] at line [32]

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception
org.apache.jasper.JasperException: An exception occurred processing [WEB-INF/user-list.jsp] at line [32]

29:             <c:forEach var="user" items="${listUser}">
30:                 <tr>
31:                     <td><c:out value="${user.ID}" /></td>
32:                     <td><c:out value="${user.Name}" /></td>
33:                     <td><c:out value="${user.HP}" /></td>
34:                     <td><c:out value="${user.Damage}" /></td>
35:                     <td>


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:610)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:499)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:379)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:327)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    web.userServlet.listUser(userServlet.java:70)
    web.userServlet.doGet(userServlet.java:54)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)


Root Cause
javax.el.PropertyNotFoundException: Property [Name] not found on type [model.User]
    javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:251)
    javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:203)
    javax.el.BeanELResolver.property(BeanELResolver.java:324)
    javax.el.BeanELResolver.getValue(BeanELResolver.java:83)
    org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:124)
    org.apache.el.parser.AstValue.getValue(AstValue.java:168)
    org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
    org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:692)
    org.apache.jsp.WEB_002dINF.user_002dlist_jsp._jspx_meth_c_005fout_005f1(user_002dlist_jsp.java:294)
    org.apache.jsp.WEB_002dINF.user_002dlist_jsp._jspx_meth_c_005fforEach_005f0(user_002dlist_jsp.java:212)
    org.apache.jsp.WEB_002dINF.user_002dlist_jsp._jspService(user_002dlist_jsp.java:159)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:379)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:327)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    web.userServlet.listUser(userServlet.java:70)
    web.userServlet.doGet(userServlet.java:54)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)


Note The full stack trace of the root cause is available in the server logs.

Here is the user-form.jsp, user-list jsp and userServlet.java code.

user-form.jsp

`<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page import="java.sql.DriverManager"%>

<html>
<body>
    <center>
        <h2>
            <a href="new">Add New User</a>
            &nbsp;&nbsp;&nbsp;
            <a href="list">List All Users</a>
            
        </h2>
    </center>
    <div align="center">
        <c:if test="${user != null}">
            <form action="update" method="post">
        </c:if>
        <c:if test="${user == null}">
            <form action="insert" method="post">
        </c:if>
        <table border="1" cellpadding="5">
            <caption>
                <h2>
                    <c:if test="${user != null}">
                        Edit User
                    </c:if>
                    <c:if test="${user == null}">
                        Add New User
                    </c:if>
                </h2>
            </caption>
                <c:if test="${user != null}">
                    <input type="hidden" name="id" value="<c:out value="${user.id}" />" />
                </c:if>            
            <tr>
                <th>User Name: </th>
                <td>
                    <input type="text" name="Name" size="50"
                            value="<c:out value="${user.Name}" />"
                        />
                </td>
            </tr>
            <tr>
                <th>HP: </th>
                <td>
                    <input type="text" name="HP" size="20"
                            value="<c:out value="${user.HP}" />"
                    />
                </td>
            </tr>
            <tr>
                <th>Damage: </th>
                <td>
                    <input type="text" name="Damage" size="20"
                            value="<c:out value="${user.Damage}" />"
                    />
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="submit" value="Save" />
                </td>
            </tr>
        </table>
        </form>
    </div>  
</body>
</html>`

user-list.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page import="java.sql.DriverManager"%>
<!DOCTYPE html>
<html>

<body>
    <center>
        
        <h2>
            <a href="new">Add New User</a>
            &nbsp;&nbsp;&nbsp;
            <a href="list">List All Users</a>
            
        </h2>
    </center>
    <form>
    <div align="center">
        <table border="1" cellpadding="5">
            <caption><h2>List of Users</h2></caption>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>HP</th>
                <th>Damage</th>
                <th>Actions</th>
            </tr>
            <c:forEach var="user" items="${listUser}">
                <tr>
                    <td><c:out value="${user.ID}" /></td>
                    <td><c:out value="${user.Name}" /></td>
                    <td><c:out value="${user.HP}" /></td>
                    <td><c:out value="${user.Damage}" /></td>
                    <td>
                        <a href="edit?ID=<c:out value="${user.ID}" />">Edit</a>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="delete?ID=<c:out value="${user.ID}" />">Delete</a>                     
                    </td>
                </tr>
            </c:forEach>
        </table>
    </div>  
    </form>
</body>
</html>

userServlet.java

package web;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.UserDao;
import model.User;

@WebServlet(name = "userServlet", urlPatterns = "/")
public class userServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private UserDao userDAO;
    
    public void init() {
        userDAO = new UserDao();
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String action = request.getServletPath();

        try {
            switch (action) {
            case "/new":
                showNewForm(request, response);
                break;
            case "/insert":
                insertUser(request, response);
                break;
            case "/delete":
                deleteUser(request, response);
                break;
            case "/edit":
                showEditForm(request, response);
                break;
            case "/update":
                updateUser(request, response);
                break;
            default:
                listUser(request, response);
                break;
            }
        } catch (SQLException ex) {
            throw new ServletException(ex);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    private void listUser(HttpServletRequest request, HttpServletResponse response)
            throws SQLException, IOException, ServletException, ClassNotFoundException {
        List<User> user = new ArrayList<>();
        user = userDAO.selectAlluser();
        request.setAttribute("listUser", user);
        RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/user-list.jsp");
        dispatcher.forward(request, response);
    }

    private void showNewForm(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/user-form.jsp");
        dispatcher.forward(request, response);
    }

    
    private void insertUser(HttpServletRequest request, HttpServletResponse response) 
            throws SQLException, IOException, ClassNotFoundException {
        String Name = request.getParameter("Name");
        String HP = request.getParameter("HP");
        String Damage = request.getParameter("Damage");
        userDAO.insertUser(new User(Name, HP, Damage));
        response.sendRedirect("list");
    }
    
    
    private void showEditForm(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, ClassNotFoundException {
        int ID = Integer.parseInt(request.getParameter("ID"));
        User existingUser = userDAO.selectUser(ID);
        RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/user-form.jsp");
        request.setAttribute("user", existingUser);
        dispatcher.forward(request, response);
 
    }


    private void updateUser(HttpServletRequest request, HttpServletResponse response) 
            throws SQLException, IOException, ClassNotFoundException {
        int ID = Integer.parseInt(request.getParameter("ID"));
        String Name = request.getParameter("Name");
        String HP = request.getParameter("HP");
        String Damage = request.getParameter("Damage");
        userDAO.updateUser(new User(ID, Name, HP, Damage));
        response.sendRedirect("list");
    }

    private void deleteUser(HttpServletRequest request, HttpServletResponse response) 
            throws IOException, ClassNotFoundException {
        int ID = Integer.parseInt(request.getParameter("ID"));
        userDAO.deleteUser(ID);
        response.sendRedirect("list");
    }

}

Leave a Comment