我在這裏瘋了試圖弄清楚爲什麼我的JSP不在表中顯示數據。像servlet連接到MySQL並填充數據,但我無法將該數據推送到JSP.setAttribute( )方法正在工作(對象在那裏)。我無法提取具體的信息並在瀏覽器中顯示格式化的表單。如果有人能指出我是如何解決這個問題的......爲什麼JSTL表達式不會加載適當的信息.Eclipse不會返回任何錯誤和整個應用程序編譯....它只是顯示空白頁面。以下您可以找到代碼。JSP顯示空白數據
提示:我正在測試是否可以推送LIST並且可以顯示對象。它工作正常,因此對象對於JSP是「可見的」。當我嘗試加載特定信息(用戶名,密碼或電子郵件)時,它將返回空白。感謝您的任何幫助/提示。
您可以在下面找到該代碼。
UserBean.java
package com.admin;
public class UserBean {
private String password;
private String firstname;
private String lastname;
private String email;
private String usertype;
private String datecreated;
private String username;
public UserBean(){};
public UserBean(String username2, String password2, String firstname2, String lastname2, String email2,
String usertype2, String datecreated2) {
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUsertype() {
return usertype;
}
public void setUsertype(String usertype) {
this.usertype = usertype;
}
public String getDatecreated() {
return datecreated;
}
public void setDatecreated(String datecreated) {
this.datecreated = datecreated;
}
}
User.DAO.java
package com.admin;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.clientdb.ConnectionManager;
public class UserDAO {
public static List<UserBean> listOfUsers()
{
List<UserBean> userList=new ArrayList<>();
String query="SELECT * FROM users";
try
{
Connection conn = ConnectionManager.getConnection();
Statement stm = conn.createStatement();
ResultSet rs = stm.executeQuery(query);
while(rs.next())
{
String username=rs.getString("username");
String password=rs.getString("password");
String firstname=rs.getString("firstname");
String lastname=rs.getString("lastname");
String email=rs.getString("email");
String usertype=rs.getString("usertype");
String datecreated=rs.getString("date_created");
UserBean user=new UserBean(username,password,firstname,lastname,email,usertype,datecreated);
userList.add(user);
}
stm.close();
rs.close();
conn.close();
}
catch(Exception ex){System.out.println(ex);}
return userList;
}}
UserAdmin.java
package com.admin;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class UserAdmin extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List<UserBean> userList = UserDAO.listOfUsers();
request.getSession().setAttribute("userList",userList);
request.getRequestDispatcher("userlist.jsp").forward(request,response);
}
}
userlist.jsp
<table class="table table-hover" style="margin-top:20px;">
<thead>
<tr>
<th>Username</th>
<th>Password</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>User Type</th>
<th>Date Created</th>
</tr>
</thead>
<tbody>
<c:forEach items="${userList}" var="user">
<tr>
<td><c:out value="${user.username}"/></td>
<td><c:out value="${user.password}"/></td>
<td><c:out value="${user.firstname}"/></td>
<td><c:out value="${user.lastname}"/></td>
<td><c:out value="${user.email}"/></td>
<td><c:out value="${user.usertype}"/></td>
<td><c:out value="${user.datecreated}"/></td>
<td>
<a href="reset.html" role="button" class="btn btn-primary">RESET</a>
<!-- <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#userDeleteModal">DELETE</button>-->
<a href="deleteUser.do?email=${user.email}" role="button" class="btn btn-danger">DELETE</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
構造是問題!不能相信我錯過了它的基礎知識。對Eclipse自動生成器沒有更多的接力。 – pjtrowski
我很高興我可以幫忙:-) – MForm