Chciałem sobie napisać swoją aplikację idąc krok po kroku wg. tego tutoriala:
Jednak po wykonaniu wszystkich czynności i próbie uruchomienia sygnalizowany jest błąd na stronie: http://localhost:18632/ePrzychodniaWebApplication/userinfo.jsp
Dostaję takie coś:
HTTP Status 500 -
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'userId'.
root causejavax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'userId'.
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.2.2 logs.GlassFish Server Open Source Edition 3.1.2.2
Coś jest nie tak z userId, ale nie mogę dojść co zrobiłem źle. Proszę o pomoc. To klasa Users:
package pl.ePrzychodnia.model;
@Entity
@Table
@NamedQueries(@NamedQuery(name="Users.getAll", query="SELECT u FROM Users u"))
public class Users implements Serializable{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int userId;
@Column
private String firstName;
@Column
private String lastName;
@Column
private String personalId;
@Column
private String email;
@Column
private String userType;
@Column
private String login;
@Column
private String pass;
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
----Reszta getterów i setterów.----
public Users(int userId, String firstName, String lastName, String personalId, String email, String userType, String login, String pass) {
this.userId = userId;
this.firstName = firstName;
this.lastName = lastName;
this.personalId = personalId;
this.email = email;
this.userType = userType;
this.login = login;
this.pass = pass;
}
public Users() {}
}
Servlet:
@WebServlet(name = "UsersServlet", urlPatterns = {"/UsersServlet"})
public class UsersServlet extends HttpServlet {
@EJB
private UsersDaoLocal usersDao;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action = request.getParameter("action");
String userIdStr = request.getParameter("userId");
int userId = 0;
if(userIdStr!=null && !userIdStr.equals(""))
userId=Integer.parseInt(userIdStr);
String firstName = request.getParameter("firstName");
String lastName = request.getParameter("lastName");
String personalId = request.getParameter("personalId");
String email = request.getParameter("email");
String userType = request.getParameter("userType");
String login = request.getParameter("login");
String pass = request.getParameter("pass");
Users user = new Users(userId, firstName, lastName, personalId, email, userType, login ,pass);
if("Add".equalsIgnoreCase(action)) {
usersDao.addUser(user);
} else if("Edit".equalsIgnoreCase(action)) {
usersDao.editUser(user);
} else if("Delete".equalsIgnoreCase(action)) {
usersDao.deleteUser(userId);
} else if("Search".equalsIgnoreCase(action)) {
user = usersDao.getUser(userId);
}
request.setAttribute("users", user);
request.setAttribute("allUsers", usersDao.getAllUsers());
request.getRequestDispatcher("userinfo.jsp").forward(request, response);
}
}
i strona jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>User information</title>
</head>
<body>
<h1>User information</h1>
<form action="./UsersServlet" method="POST">
<table>
<tr>
<td>User Id</td>
<td><input type="text" name="userId" value="${users.userId}" /></td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="firstName" value="${users.firstName}" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lastName" value="${users.lastName}" /></td>
</tr>
<tr>
<td>Personal Id</td>
<td><input type="text" name="personalId" value="${users.personalId}" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" value="${users.email}" /></td>
</tr>
<tr>
<td>User Type</td>
<td><input type="text" name="userType" value="${users.userType}" /></td>
</tr>
<tr>
<td>Login</td>
<td><input type="text" name="login" value="${users.login}" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" name="pass" value="${users.pass}" /></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="action" value="Add"/>
<input type="submit" name="action" value="Edit"/>
<input type="submit" name="action" value="Delete"/>
<input type="submit" name="action" value="Search"/>
</td>
</tr>
</table>
</form>
<br>
<table border="1">
<th>User id</th>
<th>First mame</th>
<th>Last mame</th>
<th>Personal ID</th>
<th>Email</th>
<th>User type</th>
<th>Login</th>
<th>Password</th>
<c:forEach items="$allUsers" var="user">
<tr>
<td>${user.userId}</td>
<td>${user.firstName}</td>
<td>${user.lastName}</td>
<td>${user.personalId}</td>
<td>${user.email}</td>
<td>${user.userType}</td>
<td>${user.login}</td>
<td>${user.pass}</td>
</tr>
</c:forEach>
</table>
</body>
</html>