aspose file tools*
The moose likes JSP and the fly likes form data accepted by JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "form data accepted by JSP page" Watch "form data accepted by JSP page" New topic
Author

form data accepted by JSP page

Joe McTigue
Ranch Hand

Joined: Mar 05, 2012
Posts: 52
I have an issue...
I've got a sign-in JSP page with three forms which has javascript that calls a validation servlet page
which validates entered info from the JSP page with the database. Then I need it to change back to
the JSP page moving data to different form textboxes than originally they were in if needed,
reset focus, and display a message in an alert or in the html of the JSP.

I've tried using the dispatcher.forward method from my servlet forwarding to the url with parameters
attached and this works when returning to the page, but now when I initially go to the JSP page it
expects some parameters and error out with null exception. is there better way around this?

Thanks, Joe
Saif Asif
Ranch Hand

Joined: Aug 11, 2011
Posts: 440

Hello Joe McTigue ,

Correct me if I understood it wrong, you have a JSP ( lets say login.jsp) where a user inputs his username and password and then this information is validated via a call to another servlet ( lets call it ValidationServlet.java ), and then the result of validation is shown back to the login.jsp ?

I had come across a similar scenario, and we used Ajax via java script to achieve this.I can share you what I had done.
First of all , after user entered his information on the logn.jsp , I would send an ajax request to a ValidationServlet which would authenticate the users credentials and generate some HTML based on the validation criteria . Now ajax from jquery has a success method ( which is called when a successful ajax request has been returned ) and it takes a string input . we would populate the string with the generated HTML from the validationServlet and then disaplay it on the JSP. since it was an ajax request, we didnt have to worry about sending data back and forth between different pages.

I can also share you the jquery ajax method I used.


Muhammad Saif Asif Mirza
OCJA(5/6) OCJP(6) OCJWCD(6)
Joe McTigue
Ranch Hand

Joined: Mar 05, 2012
Posts: 52
Hi Saif,

Thanks so much for your reply, but I think I might need to explain and show more code so
everyone will understand much better what i need help with.

here's what I've accomplished so far:

I've created a JSP file called Index.jsp which has three forms on it:
1.) new member sign up form
2.) current member sign in form
3.) I forgot my password form

My forms are submitted through an form button OnClick event using plain old javascript (no ajax) which brings up one of three valiadationServlets:
1.) validateNewMemberData
2.) validateCurrentMemberdata
3.) validateEmailPassword

At this point everything above works great. :-)

But now I need to go back to the Index.jsp page if there was a validation issue.
For example, if the user fills out and submits the New Member Join form and the data validation determines
the email address used is already in our database, I want to return to the index.jsp page and display the
users email address in the email address textbox of the "I forgot my password" form, and also display
an alert pop-up telling the user his email address already exists in our database please request sign-in information
and your current sign-in information will be emailed to you. followed by the email address textbox being in focus
and posibly highlighted.

What I tried and how it worked out:
I tried adding the following java to my validateNewMemberData servlet:

This did not seem to work, so I tried:

Then handle filling the textbox with a javascript triggered in the Index.jsp pages's body tag's onload event.
This seemed to work, but had a bad result on the intitial viewing of the Index.jsp page with a null exception because no parameter
would be captured in my index.jsp page's code:

Is there any other method or correction to what I'm attempting to do available?

Thanks in advance for any guidiness on this.
-Joe
 
Consider Paul's rocket mass heater.
 
subject: form data accepted by JSP page