Hi,
I'm having my login page as:

<html><head><body>
<form action="validateuser.jsp" method="POST">
username - <input type="text" name="userName">
password - <input type="password" name="passWord">
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form></body></html>

And Validator Page as :

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="java.util.*" %>
<jsp:useBean id="idHandler" class="com.suntec.tbms3.ui.Login" scope="request">
<jsp:setProperty name="idHandler" property="*"/>
</jsp:useBean>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head><body>
<%
String userName = request.getParameter("userName");
String passWord = request.getParameter("passWord");
if (idHandler.authenticate(userName, passWord))
{
response.sendRedirect("welcome.jsp");
} 
else 
{
response.sendRedirect("retry.jsp");
}
%>
</body></head>
</html>

where I'm validating the username and pass word from my DB.
Now I want to display the user login name in my welcom.jsp page. what are the modification i've to do in validator.jsp and welcome.jsp

Recommended Answers

I am new to jsp but I would do either one of the following:

1. Set the username as a session variable and then in welcome.jsp u can use

<%=session.getAttribute("userName")%>

2. Send the username in the querystring when redirecting to the welcome page then just use

request.getParameter("userName")

to display …

Jump to Post

If the redirect is to look like this

response.sendRedirect("welcome.jsp?name="+userName);

then to get the username from the query string you would use it just as u did earlier (from your original post "String userName = ......") , like this:

<%=request.getParameter("name")%>
Jump to Post

All 6 Replies

I am new to jsp but I would do either one of the following:

1. Set the username as a session variable and then in welcome.jsp u can use

<%=session.getAttribute("userName")%>

2. Send the username in the querystring when redirecting to the welcome page then just use

request.getParameter("userName")

to display it.

can you please little bit eloborative in the second point.
Here is my reedirect code :

response.sendRedirect("welcome.jsp?name="+userName);

then how could I able to display the value in the welcome.jsp

If the redirect is to look like this

response.sendRedirect("welcome.jsp?name="+userName);

then to get the username from the query string you would use it just as u did earlier (from your original post "String userName = ......") , like this:

<%=request.getParameter("name")%>

Thank you so much. It's working fine.

Your code works.. great work deek trisha

i didnt get the topic........ i redirected to a page and i have to diaplay user name in that page
i am unable to get hold of that trick.... can u elabrate with the complete code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.