gpt4 book ai didi

java - 从 servlet 到 jsp 的请求调度程序出现问题

转载 作者:行者123 更新时间:2023-12-02 08:13:49 24 4
gpt4 key购买 nike

我最近开始学习JSP和Servlet。我在使用 requestdispatcher 将 dataList(数据库中的行)转发到 JSP 时遇到问题。事实上,我的 JSP 页面有错误,我无法弄清楚。由于我正在学习,我找不到错误在哪里:

谢谢!

以下是我收到的错误

org.apache.jasper.JasperException: An exception occurred processing JSP page /dataPage.jsp at line 29

26: %>
27: <tr>
28: <td width="100"><%=itr.next()%></td>
29: <td width="100"><%=itr.next()%></td>
30: <td width="100"><%=itr.next()%></td>
31: <td width="100"><%=itr.next()%></td>
32: </tr>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:519)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:428)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
AuthenticationServlet.doPost(AuthenticationServlet.java:60)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

我的 JSP 代码是:

<table border="1" width="400">
<tr>
<td width="100"><b>Name</b>
</td>
<td width="100"><b>Contact No</b>
</td>
<td width="100"><b>SSN</b>
</td>
<td width="100"><b>Date of Birth</b>
</td>
</tr>

<%
List<String> data = (List<String>)request.getAttribute("data");
Iterator<String> itr = data.iterator();
while (itr.hasNext()) {
%>
<tr>
<td width="100"><%=itr.next()%></td>
<td width="100"><%=itr.next()%></td>
<td width="100"><%=itr.next()%></td>
<td width="100"><%=itr.next()%></td>
</tr>
<%
}
%>
</table>

我在 servlet 中的代码是

List<String> dataList = new ArrayList<String>();

try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url);
conn.createStatement();

stmt = conn.prepareStatement("SELECT name,password FROM employeeinfo WHERE name=? AND password=?");
stmt.setString(1, username);
stmt.setString(2, password);
rs = stmt.executeQuery();

if(rs != null) {
while(rs.next()) {
int i = rs.getRow();
if(i == 1) {
dataList.add(rs.getString("name"));
dataList.add(rs.getString("contactno"));
dataList.add(rs.getString("ssn"));
dataList.add(rs.getString("dob"));
}
}
} else {
out.println("Invalid User !!");
}

} catch(Exception e) {
e.printStackTrace();
}
request.setAttribute("data", dataList);
// Dispatch the request
RequestDispatcher dispatcher = request.getRequestDispatcher(page);
if(dispatcher != null) {
dispatcher.forward(request, response);
}

最佳答案

您没有在查询中选择 contactnodobssn

将您的查询修改为select name, contactno, dob, ssn from employeeinfo WHERE ...

关于java - 从 servlet 到 jsp 的请求调度程序出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6834684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com