无法在JSP页面显示数据库的内容
packageservlet;importjava.io.IOException;importjava.io.PrintWriter;importjava.util.Li...
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import service.User;
import service.UserService;
import service.UserServiceImpl;
public class ShowWenTi extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
UserService us = new UserServiceImpl();
List<User> list = us.findUserAllqes();
request.setAttribute("all", list);
request.getRequestDispatcher("web/page/wenti.jsp").forward(request, response); // tong yi get qing qiu
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
public List<User> findUserAllqes() {
List<User> all= new ArrayList<User>();
DbUtil du = null;
PreparedStatement ps = null;
ResultSet rs =null;
try {
du = new DbUtil();
String sql = "select * from tb_wenti";
ps = du.getConnection().prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
User user = new User();
user.setId(rs.getInt("wtid"));
user.setGsname(rs.getString("gsname"));
user.setGszz(rs.getString("gszz"));
user.setGsnr(rs.getString("wtnr"));
all.add(user);
}
} catch (Exception e) {
e.printStackTrace();
}try {
rs.close();
ps.close();
du.closeCon();
} catch (SQLException e) {
e.printStackTrace();
}
return all;
}
<tr>
<%
List<User> list = (List<User>)request.getAttribute("all");
if(list!=null && list.size()>0){
for(User user : list){
%>
<tr>
<td><%=user.getId() %><</td>
<td><%=user.getGsname() %></td>
<td><%=user.getGszz() %></td>
<td><%=user.getWtnr() %></td>
</tr>
<%
}
}
%>
</tr>
为什么我在打开页面的时候不能显示我要查找的数据库里面的内容呢? 展开
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import service.User;
import service.UserService;
import service.UserServiceImpl;
public class ShowWenTi extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
UserService us = new UserServiceImpl();
List<User> list = us.findUserAllqes();
request.setAttribute("all", list);
request.getRequestDispatcher("web/page/wenti.jsp").forward(request, response); // tong yi get qing qiu
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
public List<User> findUserAllqes() {
List<User> all= new ArrayList<User>();
DbUtil du = null;
PreparedStatement ps = null;
ResultSet rs =null;
try {
du = new DbUtil();
String sql = "select * from tb_wenti";
ps = du.getConnection().prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
User user = new User();
user.setId(rs.getInt("wtid"));
user.setGsname(rs.getString("gsname"));
user.setGszz(rs.getString("gszz"));
user.setGsnr(rs.getString("wtnr"));
all.add(user);
}
} catch (Exception e) {
e.printStackTrace();
}try {
rs.close();
ps.close();
du.closeCon();
} catch (SQLException e) {
e.printStackTrace();
}
return all;
}
<tr>
<%
List<User> list = (List<User>)request.getAttribute("all");
if(list!=null && list.size()>0){
for(User user : list){
%>
<tr>
<td><%=user.getId() %><</td>
<td><%=user.getGsname() %></td>
<td><%=user.getGszz() %></td>
<td><%=user.getWtnr() %></td>
</tr>
<%
}
}
%>
</tr>
为什么我在打开页面的时候不能显示我要查找的数据库里面的内容呢? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询