473,372 Members | 1,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

How to Retain the UserName text box ?

Hi All

I am new to JSP Js and Web

I need to retain my Username text in my text box when the user types the Wrong username and password

I tried several methods.. I didn get the solution.. I finally sent the username in url to get it back

Is there a way to retain the username text after the data being posted?

Please suggest me some details and examples..

Thanks in Advance
Apr 4 '09 #1
13 10628
2,476 2GB
See when you are authenticating something then you must need to use POST method. You use a JSP or HTML for log in screen then Post the data for authentication to a action JSP page or Controller then forward back the same view page(what you used for login screen) so that you will show the user name in the text with some error messages.
Did you get it ?
Apr 4 '09 #2
I do whatever you said ... In php we have a coding option like
<input type="text" name="username" value="<?php echo @$_POST['username']; ?>" />

There is some option in FTL also

Is there any option in JSP files to get back the post values like the above code in php where we get the value of the post...

Did you get my question?

I am struggling with it.
Can anyone help?
Apr 4 '09 #3
Can anyone help me out in this issue

I ve got only one response so far...

Is it impossible in JSP?

Can anyone get me a method to get the prevoius POST values as we get in php and ftl or so

Pl help me out

Apr 6 '09 #4
2,476 2GB
I am not familiar with PHP so don't know about FTL ;)
Actually your forwarded page should be the login page if authentication fails. Otherwise it will be something else. When you forwarding the login page on authentication failure then you simply place the user name by "request.getParameter("userName")" ;)
Apr 6 '09 #5
Hi ,

Always the response.getParameter("ANYItem"); is returning null
For example i have a hidden field Its name is"h" and id is "h"

i give request.getParameter("h");

It always returns me NULL

What could be the reason... If that had worked i would ve solved my issue but that failed ... What could be the reason for the returning of NULL value in response.getParameter(); I think of a reason.. I post some POST data to server and the server responds, If the credentials are wrong then the its redirectd to the login Page itself. While resending the old POST data sent from server might be lost. Am i right or not? If not pl correct me.

I really don know why i m getting NULL values in the getParameter call

Apr 6 '09 #6
13,262 8TB
Did you use RequestDispatcher.forward? Set the values as attributes in the servlet using
Expand|Select|Wrap|Line Numbers
  1. request.setAttribute("h", value);
then get the value in the jsp using
Expand|Select|Wrap|Line Numbers
  1. request.getAttribute("h");
Apr 6 '09 #7
I redirect to my login page using ServeletActioncontext.getResponse.sendRedirect("lo ginPage");
from my java class

How to set the attribute of h here ..

My loginpage is a jsp file..called login.jsp from there i can get my attribute as request.getAttribute("h"); but i couldn get u where to set it...

I am new to Web
Thats why

Apr 6 '09 #8
i think you should read this book; http://pdf.moreservlets.com/ All the issues JSP / Servlet are explained in great detail.
Apr 6 '09 #9
13,262 8TB
You set it in the servlet you are posting to. However, when you sendRedirect, a new request is created so the data you set in the request will no longer be available. You can store the values as attributes in the session if you want them to persist across multiple requests.
Apr 6 '09 #10
2,476 2GB
Expand|Select|Wrap|Line Numbers
  1. <form name=loginForm action="some_servlet or JSP" method="POST">
  2. <input type=text name=userName value="<%=request.getParameter("userName")!=null?request.getParameter("userName"):""%>"/>
  3. <input type=password name=password/>
  4. </form>
That would be your form code..you submit the form and return back the same page if authentication fails no need to add any attribute into "request" scope.

And don't use "sendRedirect" why are you redirecting the instead of forwarding the page?
Apr 6 '09 #11


Is using sendRedirect the cause of problem?

Hoe to do the forwarding from my java code...

Which class gives the method of "forwarding" instead of redirecting?

Thanks for the help

Apr 7 '09 #12
2,476 2GB
Send redirect causes a new request but forward does not. So you will be still able to access the "request" object.
If you use JSP then use "jsp:forward" tag otherwise use "RequestDispatcher".
Look for google ;)
Apr 7 '09 #13
11,448 Expert 8TB
See this:

Expand|Select|Wrap|Line Numbers
  1. // at the end of your doGet/doPost method:
  2. getServletContext().getRequestDispatcher("/jsps/yourjsp.jsp").forward(request, response);
Note that you can pass the same request and response objects. You can set new values in them as well and they are passed (forwarded) to your jsp. One of those values should be the username so the login jsp can set and display it.

kind regards,

Apr 7 '09 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

by: M.E. | last post by:
Hi I have 4 radio buttons. each button to determine which page to go to. But before page open user enters username in a text box. So when submitted, Page opens relevant to that user displaying...
by: Renuka | last post by:
I have a Login Page with a Username text box and another one for Password. How can I have the cursor in the Username text box once the page loads. Do I need to have a client side script?? ...
by: Joebloggs | last post by:
Hi I am trying to do an ldap lookup. I can pick up the domain name in the standard format DOMAIN\USERNAME. The problem is the company I work for expects the query in the format DOMAIN:USERNAME....
by: Andy G | last post by:
I am trying to validate a username text box. This text box comes off of a registration form where the user types in a username, I want to validate that they used between 6 and 15 alphanumeric...
by: Dhruba Bandopadhyay | last post by:
I am using a <asp:TextBox TextMode="Password"... etc. however it doesn't retain it's text through postbacks, whereas other textboxes do. Does anyone know how to retain the text?
by: Michael | last post by:
Hi, I am getting a strange error. Last night when I left work this was working perfectly. This morning when I try to run this code in VS2005, it comes up with an error saying "The name 'UserName'...
by: pankajit09 | last post by:
Hi I am implementing a search functionality. Whenever a user types a text to search and then clicks enter I want the textbox to retain the text after page reloading just like Google. How to...
Steve Kiss
by: Steve Kiss | last post by:
I have a site in which there are two asp textboxes as follows: <asp:TextBox runat="server" ID="UserName" /> <asp:TextBox id="Email" runat="server" ...
by: =?Utf-8?B?U2hydXRpIERlc2hwYW5kZQ==?= | last post by:
I am developing an application in vb.net 2005 to send email via outlook. The mail body contains key - value pairs like Account Number : 232323 CRS Number : 872732 Name :...
by: VigneshMohan | last post by:
Hi All I am new to JSP Js and Web I need to retain my Username text in my text box when the user types the Wrong username and password I tried several methods.. I didn get the solution.. I...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.