Raftor
asked on
passing values to other pages
in a html/jsp website how would you pass information from a 'login' page down several pages to a 'change password' page using jsp
ASKER
ive done that but passing the name on after that is the problem because <% String p_reportnum = request.getParameter("repo rtnum"); %> doesnt seem to want to work for me.
Have you inported the drivers on the second page?
How about you list your code
How about you list your code
<%@ page import="java.sql.*,oracle. jdbc.drive r.*, oracle.sql.*,java.io.*,jav ax.sql.*,j ava.awt.*, java.util. *"%>
This is the import string that I use for a lot of my projects
This is the import string that I use for a lot of my projects
ASKER
good stuff ill see what i can do and get back to you.
ASKER
there are three jsp pages involved the first is login.jsp that sends the users information to a page where it is stored. The second page is admin_home_page.jsp where i want to have the following fields passed to. These lines get the values from the login page successfully but passing them on is the problem.
String strUserName = request.getParameter("txtU sername");
String strPassword = request.getParameter("txtP assword");
The following is login_successful.jsp and admin_home_page.jsp respectively.
////////////////////////// ////////// ////////// ////////lo gin_succes sful.jsp// ////////// ////////// ////////// ////////// ////////// ////
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%
try
{
String strUserName = request.getParameter("txtU sername");
String strPassword = request.getParameter("txtP assword");
if (strUserName != null)
out.print("User Name: " +strUserName);
int login = 0;
String inServer = "localhost";
String inDBName = "colin";
String DATABASE_URL = "jdbc:mysql://" + inServer + ":3306/" + inDBName;
Class.forName("com.mysql.j dbc.Driver ").newInst ance();
Connection con = DriverManager.getConnectio n(DATABASE _URL, "colinrafter", "keyhole");
Statement stmt = con.createStatement();
Statement state = con.createStatement();
ResultSet rs1 = stmt.executeQuery("select password from members where userName like \""+strUserName+"\"");
String passwordtocompare = "";
if (rs1.next())
{
passwordtocompare = rs1.getString(1);
if((passwordtocompare.comp areToIgnor eCase(strP assword) == 0) && (strUserName.compareToIgno reCase("GH icks")==0) )
login = 2;
else if(passwordtocompare.compa reTo(strPa ssword) == 0)
login = 1;
else
login = 0;
}
if(login == 0)
response.sendRedirect("log in_error.j sp");
else if(login == 1)
response.sendRedirect("hom e_page.jsp ");
else if(login == 2)
response.sendRedirect("adm in_home_pa ge.jsp");
}
catch (ClassNotFoundException cnfe) {out.println(cnfe.toString ());}
catch (SQLException sqle) {out.println(sqle.toString ());}
%>
////////////////////////// ////////// ////////// ////////// /////////a dmin_home_ page.jsp// ////////// ////////// ////////// //////
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<HTML>
<HEAD>
<TITLE> Administrator Home Page </TITLE>
</HEAD>
<CENTER>
<!-- This is where i want to be able to retrieve the name from the previous page. -->
<%
String strAdministrator = request.getParameter("strU serName");
out.println("strAdministra tor is: " + strAdministrator);
%>
<IMG ALIGN="center" SRC="images/header.bmp">
<FONT SIZE="+2" COLOR="9400D3 "><B><U><P> Administrator Home Page </B></U></font>
<div id=Layer1 style="HEIGHT: 244px; LEFT: 71px; POSITION: absolute; TOP: 213px; WIDTH: 137px; Z-INDEX: 1">
<p><a href="admin_home_page.jsp" ><img border=0 height=32 src="images/button.gif" width=105 img></a>
</p>
<p><a href="manage_current_reque sts.jsp">< img border=0 height=32 src="images/button.gif" width=105 img></a>
</p>
<p><a href="view_previous_reques ts.jsp"><i mg border=0 height=32 src="images/button.gif" width=105 img></a><a href="book_request_head.as p">
</a></p>
<p><a href="view_member_details. jsp"><img border=0 height=32 src="images/button.gif" width=105 img></a></p>
<p><a href="manage_budgets.jsp"> <img border=0 height=32 src="images/button.gif" width=105 img></a></p>
<p><a href="manage_budgets.jsp"> <img border=0 height=32 src="images/button.gif" width=105 img></a></p>
<p><a href="change_password.jsp" ><img border=0 height=32 src="images/button.gif" width=105 img></a></p>
<p><a href="login.jsp"><img border=0 height=32 src="images/button.gif" width=105 img></a></p>
<p> </p>
<p> </p>
<p> </p>
</div>
<FONT color=#940d00 size=+2><B><U> </u></B></FONT> <FONT color=#000000 size=+0>
<P>
</FONT><P><FONT color=#000000 size=+0>Welcome to the GMIT Administration Home Page </font><br><br>
Please choose one of the options from the left
<P><A href="mailto:colinrafter@y ahoo.com"> <FONT color=blue>Web design by Colin Rafter 2003</font></A></P>
</CENTER>
</BODY>
</HTML>
String strUserName = request.getParameter("txtU
String strPassword = request.getParameter("txtP
The following is login_successful.jsp and admin_home_page.jsp respectively.
//////////////////////////
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%
try
{
String strUserName = request.getParameter("txtU
String strPassword = request.getParameter("txtP
if (strUserName != null)
out.print("User Name: " +strUserName);
int login = 0;
String inServer = "localhost";
String inDBName = "colin";
String DATABASE_URL = "jdbc:mysql://" + inServer + ":3306/" + inDBName;
Class.forName("com.mysql.j
Connection con = DriverManager.getConnectio
Statement stmt = con.createStatement();
Statement state = con.createStatement();
ResultSet rs1 = stmt.executeQuery("select password from members where userName like \""+strUserName+"\"");
String passwordtocompare = "";
if (rs1.next())
{
passwordtocompare = rs1.getString(1);
if((passwordtocompare.comp
login = 2;
else if(passwordtocompare.compa
login = 1;
else
login = 0;
}
if(login == 0)
response.sendRedirect("log
else if(login == 1)
response.sendRedirect("hom
else if(login == 2)
response.sendRedirect("adm
}
catch (ClassNotFoundException cnfe) {out.println(cnfe.toString
catch (SQLException sqle) {out.println(sqle.toString
%>
//////////////////////////
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<HTML>
<HEAD>
<TITLE> Administrator Home Page </TITLE>
</HEAD>
<CENTER>
<!-- This is where i want to be able to retrieve the name from the previous page. -->
<%
String strAdministrator = request.getParameter("strU
out.println("strAdministra
%>
<IMG ALIGN="center" SRC="images/header.bmp">
<FONT SIZE="+2" COLOR="9400D3 "><B><U><P> Administrator Home Page </B></U></font>
<div id=Layer1 style="HEIGHT: 244px; LEFT: 71px; POSITION: absolute; TOP: 213px; WIDTH: 137px; Z-INDEX: 1">
<p><a href="admin_home_page.jsp"
</p>
<p><a href="manage_current_reque
</p>
<p><a href="view_previous_reques
</a></p>
<p><a href="view_member_details.
<p><a href="manage_budgets.jsp">
<p><a href="manage_budgets.jsp">
<p><a href="change_password.jsp"
<p><a href="login.jsp"><img border=0 height=32 src="images/button.gif" width=105 img></a></p>
<p> </p>
<p> </p>
<p> </p>
</div>
<FONT color=#940d00 size=+2><B><U> </u></B></FONT> <FONT color=#000000 size=+0>
<P>
</FONT><P><FONT color=#000000 size=+0>Welcome to the GMIT Administration Home Page </font><br><br>
Please choose one of the options from the left
<P><A href="mailto:colinrafter@y
</CENTER>
</BODY>
</HTML>
ASKER
Sorry i made a mistake. I want to pass the user name from login_successful.jsp that originally retrieved the name from login.jsp and pass it to admin_home_page.jsp.
Ok I just glanced through it really quick, but you need to set a hidden field
<INPUT TYPE=hidden NAME=user VALUE="<%= strUsername %>">
then submit to the next page just like before
I have a meeting at 4:15 so i hope this helps, otherwise i may be back before 5:00, if not I will check your code further tomorrow!
<INPUT TYPE=hidden NAME=user VALUE="<%= strUsername %>">
then submit to the next page just like before
I have a meeting at 4:15 so i hope this helps, otherwise i may be back before 5:00, if not I will check your code further tomorrow!
ASKER
ok cheers ill see what i can do with that.
ASKER
sorry but im gonna need your expert help on how to use that hidden form field.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>>try passing them in the url:
it says:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localh
response.sendRedirect("adm
^
Is that the right format?
> response.sendRedirect("adm in_home_pa ge.jsp?str UserName=< %= strUserName
wheres the rest of the line?
response.sendRedirect("adm in_home_pa ge.jsp?str UserName=< %= strUserName %>");
wheres the rest of the line?
response.sendRedirect("adm
ASKER
Its ok i figured it out you were missing quotes around strUserName like this
response.sendRedirect("adm in_home_pa ge.jsp?str UserName=" +strUserNa me+"");
response.sendRedirect("adm
doh, that'll teach me to start work before coffee :)
ASKER
can someone explain how hidden forms work and how storing values in sessions works?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That code worked perfectly but i was wondering what would happen if someone didnt hit 'logout' and instead hit the close button on the top left of the page? Would the sessions be reset or would they remain for the next session?
ASKER
top right sorry.
AFAIK, session is based on browser window, if the browser is closed, the session will be destroyed.
> Would the sessions be reset or would they remain for the next session?
the session would remain until it timed out.
the session would remain until it timed out.
<INPUT TYPE=submit VALUE="Submit">
</FORM>
Page 2 needs a way to receive the information
<% String p_reportnum = request.getParameter("repo