• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Simple login form project - all attributes are null and HTTP Status 404 error in some cases

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm a new Java user and I'm trying to code a simple login page. In first page (NewFile.jsp) users should enter their username and password and should click on "login", or click on "sign up".

1.) If user enters his username and password correctly, a login page (LoginPage.jsp) appears and says "welcome null" but it should show the name of that user instead of null.

2.) In that login page there is an edit button to edit profile information. When I clicked on it, every information is "null" and when I edit them and click on "Submit" button;

HTTP Status 404 -
type Status report
message
description The requested resource () is not available.
GlassFish Server Open Source Edition 3.1.2

that message appears.

3.) If I click on "Sign Up" button at the beginning, a registration jsp (SignUpPage.jsp) appears. After filling up text boxes and clicking on "Submit", same Status 404 screen appears.

I created a mysql database called "loginpage" using xampp. In that database there is a table called "users" and it has un, pass, name, surname, email and degree attributes.

Here is a screenshot of my project explorer:


Here is my code:

1. NewFile.jsp


2.LoginPage.jsp


3. LoginServlet.java


4. LoginDao.java


5. SignUpPage.jsp


6. Registration.java


7. EditPage.jsp


8. Edit.java


9. EditDetails.java


10. UpdateUser.java

11. glassfish-web.xml
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

How come you are getting the as


This practically gets the session if it already exists, which at first (eg at the login page) there is no session. You should remove the false part.

Also in the jsp pages (those need authenticated content) add in the session attribute for the @page declaration



This way subsequent jsp pages will be session-aware until user logs out or session times out.
 
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Koray,
Remove the doGet method in LoginServlet and tell the new behaviour.
 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for welcome K.

I have corrected the things you mentioned but still have same problems.

My code is a bit complicated because I'm trying to learn own my own from lots of websites so there can be lots of unrelated or non functional codes. Sorry for that
 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Ngom wrote:Hi Koray,
Remove the doGet method in LoginServlet and tell the new behaviour.


Hey Paul, nothing is changed.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What says the title of the LoginPage.jsp that diplays Welcome null?
 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it still says welcome null because of that part in LoginPage.jsp
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You want to display the name or the username? Because there is no field passed from LoginServlet on which you can apply a request.GetParameter(). Maybe you need to connect to the database to retrieve it. You could make LoginDao.validate() to return the name which you will attach to LoginPage as LoginPage?name=nameReturned. The values set in the session are un and pass.
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK let's just focus on NewFile.jsp -> login servlet -> LoginPage.jsp.

NewFile.jsp is just a form which you got. Yet those <@page import ....> can be removed at the top.

Login Servlet:
1) can just have the doPost() method. Because ideally this servlet won't be triggered by users typing it in the address bar.
2) don't need the explicit constructor. Remove that.
3) doGet() method can be removed.



LoginPage.jsp
1) add session="true" to <%@ page
2) why need to wrap "Hello...." in a form calling LoginServlet?
3) add line <% request.getSession(); %> before using session variable


That should get you started to a more simpler page/servlet.
 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Ngom wrote:You want to display the name or the username? Because there is no field passed from LoginServlet on which you can apply a request.GetParameter(). Maybe you need to connect to the database to retrieve it. You could make LoginDao.validate() to return the name which you will attach to LoginPage as LoginPage?name=nameReturned. The values set in the session are un and pass.



I wanna display the name but I didn't understand what do you want me to do
 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have changed all the things you said K. Tsang. I am trying to solve these problems for days and I don't know what to do.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


status = rs.next();

while(rs.next()) {
...



This needs to be changed also otherwise you may never enter the while loop. I think an if clause is sufficient. This is in LoginDao.java
It is better to change the status variable value inside the loop like the following


If you do this, you can then call LoginDao.getName() inside LoginServlet.java


Then get the session value in the LoginPage.jsp

Hope i will be understood.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Koray,
Was step 1 solved? Can we proceed to step 2 of errors?
Regards
 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Paul, thanks for your help. I added the things you want me to add but due to the errors, I had to add "static" for both variable and method name like, static String name = ""; and public static String getName().
It was like;
Login successful!!!
Hello, null
Welcome null
before. And now it is like;
Login successful!!!
Hello,
Welcome null.
Still name attribute isn't displayed.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your LoginPage should look like this

 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I directly copied and pasted your code on LoginPage.jsp and it is now:
Login successful!!!

Hello,

Welcome.

Can it be because of my web.xml? I didn't change or add anything on that part.
 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also add a new jsp which shows entire database table to see if I can connect database or not. And it displays every users with every attributes.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post your LoginDao.java and LoginServlet.java. You also need to define the servlets mapping in web.xml if you want to call them from browser which is not our case.
 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here they are:

LoginDao.java:


LoginServlet.java

 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Remove this line from LoginDao.java
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Remove this line from LoginDao.java
 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Woohoo it worked!
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Woohoo it worked!



Well, that's good news. Can you figure out the solution for step 2 errors?
 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I fixed it a bit. It was displaying null values for attributes, now it displays name, surname etc. But it still gives status 404 error when I click on submit button.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post EditPage.jsp and a full description of the error message you are having.
 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this code in the Internet and changed some parts. Also, I just noticed another error. When I clicked edit button all the attributes are coming except degree. Even I write selected: <option value="<%=session.getAttribute("degree")%>" selected>

EditPage.jsp


Registration.java


EditDetails.java


UpdateUser.java




 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this for EditPage.jsp and tell me if the field degree shows. I assume the possible values of degree in table are associatedegree, bachelordegree, masterdegree and doctoraldegree.

 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It always shows Associate Degree is selected.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the previous post, try this for EditPage.jsp

 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It still shows Associate Degree for all users. That problem is not that important. You can skip this one
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


That problem is not that important. You can skip this one



No, let's not skip it. What are the possible values of degree column in table?
 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That column is varchar(30) in table if you need that. Combo box consists of Associate Degree, Bachelor's Degree, Master's Degree and Doctoral Degree.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have not given the actual values stored in degree column. Are they associatedegree, bachelordegree,masterdegree or doctoraldegree?
 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes but there are "s" in both "bachelorsdegree" and "mastersdegree". I directly copied and pasted this combo box from my SignUpPage.jsp. I didn't mention them in anywhere else.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From your indication, the values of degree in table are associatedegree, bachelorsdegree, mastersdegree and doctoraldegree. I am not talking about the content of the combo box. So the EditPage.jsp should then read:



Try test it again and tell what happens.
 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still gives Associate Degree, though user's degree is Bachelor's Degree.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What! Please let's do some debugging. Insert in page EditPage.jsp the following code:



and let us know the value of degree in session.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Koray,
Please tell the value of session variable degree that is printed after you have inserted the code i gave you.
 
K. Karacakaya
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It gives Bachelor's Degree.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OIC, then the values in your options are not correct unless you change them before inserting inside the database in the Edit class.
That is why, i was asking that you give the possible values of the column degree in table. Run a 'select distinct degree from users;' in database and post the results.
reply
    Bookmark Topic Watch Topic
  • New Topic