0

我试图从一个 JSP 页面移动到另一个,但在用户点击名称和密码后,它只是停留在同一页面。这是完整的代码:

这里是 index.jsp:我从这个页面开始

<%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<title>Insert title here</title>
</head>
<body>
<form action="LoginServlet" method="POST">
        First Name: <input type="text" name="firstName" size="20"><br>
        Last Name: <input type="text" name="lastName" size="20">
        <br><br>
        <input type="submit" value="Submit">
</form> 

</body>
</html>

这是 student.jsp :我想移到这个页面

<%@ page contentType="text/html; charset=utf-8" language="java"%>
<jsp:useBean id="userBean" class="UserBean" scope="session" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet"  type="text/css" href="css/style2.css" />
<title>Student Access Details</title>
</head>

<body>
<table>
    <tr>
        <td rowspan="4" class="align_top"><img src="img/photo.jpg" width="120" height="120" /></td>
        <td class="align_top">Student name: </td>
        <td class="bold"><%= userBean.getFirstName() %> <%= userBean.getLastName() %></td>
    </tr>
    <tr>
        <td class="align_top">University ID: </td>
        <td><%= userBean.getUid() %></td>
    </tr>       
    <tr>
        <td class="align_top">Address: </td>
        <td><%= userBean.getAddress1() %><br />
            <%if(userBean.getAddress2() != null)
                {%>
                <%= userBean.getAddress2() %><br /><%}%>            
            <%= userBean.getCity() %><br />
            <%= userBean.getPostCode() %><br />
        </td>
    </tr>
    <tr>
        <td class="align_top">Contact: </td>
        <td>Tel: <%= userBean.getPhone() %><br />
            Email: <%= userBean.getEmail() %>
        </td>
    </tr>            
</table>
</body>
</html>

我正在使用Tomcat ,JDBC , XAMPP and MySQL.

当我从浏览器运行这一行时:http://localhost:8080/MyFirstServlet

我进入此页面并点击homer& simpson第一页

然后我就呆在同一页上,在这里:

第二张图片 - 同一页

知道我做错了什么吗?谢谢 !

4

2 回答 2

1

您的 validate(...) 方法将始终为 homer 和 simpson 返回 false ,尝试其他用户名/密码

于 2012-07-01T14:59:00.403 回答
0

在 HTML 表单中的 HTML 代码操作参数中使用适当的操作,以将表单提交到它应该去的地方

而不是更改动作参数值并尝试

<form action="LoginServlet" method="POST">

用这个

<form action="student.jsp" method="POST">
于 2013-08-19T11:59:47.900 回答