473,406 Members | 2,371 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,406 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
Vignesh.M
Apr 4 '09 #1
13 10635
dmjpro
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
@dmjpro
I do whatever you said ... In php we have a coding option like
<code>
<input type="text" name="username" value="<?php echo @$_POST['username']; ?>" />
</code>

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?
-
Thanks
Vignesh.M
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

-
Vignesh.M
Apr 6 '09 #4
dmjpro
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
@dmjpro
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

Thanks
-
Vignesh.M
Apr 6 '09 #6
r035198x
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
@r035198x
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

-
Vignesh.M
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
r035198x
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
dmjpro
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>
  5.  
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
@dmjpro

Hi

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

Vignesh.M
Apr 7 '09 #12
dmjpro
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
JosAH
11,448 Expert 8TB
@VigneshMohan
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);
  3.  
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,

Jos
Apr 7 '09 #14

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

Similar topics

3
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...
6
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?? ...
2
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....
1
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...
3
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?
3
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'...
1
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...
1
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" ...
2
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 :...
1
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.