0

I'm trying to move from one JSP page to another , but after the user hits the name and the password , it just stays the the same page . Here's the complete code:

Here's index.jsp: I'm starting from this page

<%@ 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>

Here's is student.jsp : I want to move to this page

<%@ 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>

I'm using Tomcat ,JDBC , XAMPP and MySQL .

When I run from the browser this line : http://localhost:8080/MyFirstServlet

I enter this page and I hit homer & simpson : First page

Then I just stay at the same page , here :

Second pic - the same page

Any idea what I'm doing wrong ? Thanks !

JAN
  • 21,236
  • 66
  • 181
  • 318
  • What servlet code got executed and what not? – BalusC Jul 01 '12 at 13:33
  • This is broken on multiple levels, the first being treating servlets like they're thread-safe and exclusive per-user/connection/etc. – Dave Newton Jul 01 '12 at 13:37
  • @DaveNewton sorry but I didn't understand exactly , what did I do wrong ? – JAN Jul 01 '12 at 13:40
  • Dave is right, the servlet class design is totally wrong, but that doesn't explain why it is seemingly not invoked. The design is a different problem which can be better understood by carefully reading this answer: http://stackoverflow.com/questions/3106452/how-do-servlets-work-instantiation-session-variables-and-multithreading/3106909#3106909 – BalusC Jul 01 '12 at 13:46

2 Answers2

1

Your validate(...) method will always return false for homer & simpson , try other username/password

0

use proper action in the HTML code action parameter in HTML form for the form submit where it should go

Instead of change the action parameter value and try

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

use this

<form action="student.jsp" method="POST">
kapil das
  • 2,061
  • 1
  • 28
  • 29