prain
asked on
jspFrom question
I am invoking a Servlet from a jsp. Why is the jspFrom parameter that getting into to the doPost() of the servlet
is null? What could be the reason?
I am using this statement inside doPost()
fromJSP = req.getParameter ("jspFrom");
System.out.println("fromJS P : " + fromJSP);
and the I use System.out.println() to direct the string output to a log file in the /logs directory.
my output says.
fromJSP : null
What Am I doing wrong here?
is null? What could be the reason?
I am using this statement inside doPost()
fromJSP = req.getParameter ("jspFrom");
System.out.println("fromJS
and the I use System.out.println() to direct the string output to a log file in the /logs directory.
my output says.
fromJSP : null
What Am I doing wrong here?
ASKER
<HTML>
<HEAD>
<TITLE>A SYSTEM</TITLE>
<style type = "text/css">
body {
font-family : tahoma, helvetica, arial, sans-serif;
}
table, tr, td {
font-size : .9em;
border: 3px groove;
padding: 5px;
background-color : #dddddd;
}
</style>
</HEAD>
<BODY>
<FORM Method="POST"
Action="http://localhost:8080/UserSystems/UserLogin" ID="form1" Name="form1">
<CENTER>
<div><img src="http://localhost:8080/UserSystems/images/DR_Startup_Banner.gif" ></div>
<div><img src="http://localhost:8080/UserSystems/images/logon_header_home.gif" width="162" height="15" alt="Returning Users: Log On" border="0"></div>
<TABLE Cellspacing="5" Cellpadding="2" Border="2">
<TR>
<TD> User ID:</TD>
<TD><INPUT Type="text" Name="UserID" Size="12" MaxLength="20"></TD>
</TR>
<TR>
<TD> Password:</TD>
<TD><INPUT Type="password" Name="PassWord" size="12" maxlength="20"></TD>
</TR>
<TR>
<TD>
</TD>
<!-- Green Log on Button -->
<TD><div class="homeLogonbutton"><! a href="https://localhost:8080/UserSystems/DRSuccessfulLogon.jsp?LOB=RBGLogon"><input type="image" src="http://localhost:8080/UserSystems/images/logon_button_home.gif" alt="log on" tabindex="3" width="57" height="16" vspace="0" border="0" onClick="return validateandsetcookie(docum ent.logonf orm.usr_na me, document.logonform.usr_pas sword.valu e, document.logonform.remembe r.checked, '',document.logonform)"><! /a></div> </TD>
</TABLE>
<!-- This page is requested by the user if the user forgot the password -->
<div class="logonQs"><a href="http://localhost:8080/UserSystems/DRForgotUserIDPassword.jsp?LOB=RBGLogon" class="pageText"><font size="2" color="blue" face="arial">Forgot User ID/Password?</a></div>
<!-- This New Registration User -->
<p></p>
<div class="newUserQs"><a href="http://localhost:8080/UserSystems/DRNewRegistration.jsp?LOB=RBGLogon" class="pageText"><font size="3" color="red" face="arial"><b>New User?. Please Register!</a></div>
<!--This is the gap between before the footer line -->
<p><br><br></p>
<div><img src="http://localhost:8080/UserSystems/images/footer.gif" ></div>
<!-- The display string below footer -->
<font size="1" color="red" face="arial">XXXXXXXXXX<br >
<font size="1" color="gray" face="arial">Created by XXXXXX @2006
</CENTER>
</FORM>
<SCRIPT language="javascript">
<!--
document.form1.UserID.focu s()
//-->
</SCRIPT>
</BODY>
</HTML>
and the UserLogin.java servlet's
doPost() is given below
public void doPost (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
userID = req.getParameter("UserID") ;
passWord = req.getParameter("PassWord ");
fromJSP = req.getParameter ("jspFrom");
System.out.println("user ID : " + userID);
System.out.println("passWo rd : " + passWord);
System.out.println("fromJS P : " + fromJSP);
HttpSession session = req.getSession (true);
if (userID.equals ("demo") && passWord.equals ("demo"))
{ // successful
System.out.println("Pass Word Successful");
session.setAttribute ("isDemoLogin", "Yes");
session.setAttribute ("UserID", userID);
// OKAY ... forward to JSP from "fromJSP"
res.sendRedirect (JSPLoc + fromJSP);
}
else
{ // unsuccessful
System.out.println("Pass Word Unsuccessful");
session.setAttribute ("isDemoLogin", "No");
session.setAttribute ("UserID", "");
invalidID = true;
doGet (req, res);
}
} // end of doPost() method
<HEAD>
<TITLE>A SYSTEM</TITLE>
<style type = "text/css">
body {
font-family : tahoma, helvetica, arial, sans-serif;
}
table, tr, td {
font-size : .9em;
border: 3px groove;
padding: 5px;
background-color : #dddddd;
}
</style>
</HEAD>
<BODY>
<FORM Method="POST"
Action="http://localhost:8080/UserSystems/UserLogin" ID="form1" Name="form1">
<CENTER>
<div><img src="http://localhost:8080/UserSystems/images/DR_Startup_Banner.gif" ></div>
<div><img src="http://localhost:8080/UserSystems/images/logon_header_home.gif" width="162" height="15" alt="Returning Users: Log On" border="0"></div>
<TABLE Cellspacing="5" Cellpadding="2" Border="2">
<TR>
<TD> User ID:</TD>
<TD><INPUT Type="text" Name="UserID" Size="12" MaxLength="20"></TD>
</TR>
<TR>
<TD> Password:</TD>
<TD><INPUT Type="password" Name="PassWord" size="12" maxlength="20"></TD>
</TR>
<TR>
<TD>
</TD>
<!-- Green Log on Button -->
<TD><div class="homeLogonbutton"><!
</TABLE>
<!-- This page is requested by the user if the user forgot the password -->
<div class="logonQs"><a href="http://localhost:8080/UserSystems/DRForgotUserIDPassword.jsp?LOB=RBGLogon" class="pageText"><font size="2" color="blue" face="arial">Forgot User ID/Password?</a></div>
<!-- This New Registration User -->
<p></p>
<div class="newUserQs"><a href="http://localhost:8080/UserSystems/DRNewRegistration.jsp?LOB=RBGLogon" class="pageText"><font size="3" color="red" face="arial"><b>New User?. Please Register!</a></div>
<!--This is the gap between before the footer line -->
<p><br><br></p>
<div><img src="http://localhost:8080/UserSystems/images/footer.gif" ></div>
<!-- The display string below footer -->
<font size="1" color="red" face="arial">XXXXXXXXXX<br
<font size="1" color="gray" face="arial">Created by XXXXXX @2006
</CENTER>
</FORM>
<SCRIPT language="javascript">
<!--
document.form1.UserID.focu
//-->
</SCRIPT>
</BODY>
</HTML>
and the UserLogin.java servlet's
doPost() is given below
public void doPost (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
userID = req.getParameter("UserID")
passWord = req.getParameter("PassWord
fromJSP = req.getParameter ("jspFrom");
System.out.println("user ID : " + userID);
System.out.println("passWo
System.out.println("fromJS
HttpSession session = req.getSession (true);
if (userID.equals ("demo") && passWord.equals ("demo"))
{ // successful
System.out.println("Pass Word Successful");
session.setAttribute ("isDemoLogin", "Yes");
session.setAttribute ("UserID", userID);
// OKAY ... forward to JSP from "fromJSP"
res.sendRedirect (JSPLoc + fromJSP);
}
else
{ // unsuccessful
System.out.println("Pass Word Unsuccessful");
session.setAttribute ("isDemoLogin", "No");
session.setAttribute ("UserID", "");
invalidID = true;
doGet (req, res);
}
} // end of doPost() method
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
I think you can change all your urls to be relative to your container.
<div><img src="http://localhost:8080/UserSystems/images/footer.gif" ></div>
to
<div><img src="/UserSystems/images/f ooter.gif" ></div>
<div><img src="http://localhost:8080/UserSystems/images/footer.gif" ></div>
to
<div><img src="/UserSystems/images/f
That way your code wil work locally and remotely.
radarsh deseves all points.
ASKER
Fixed it. Thanks for the hints.
prain
prain
________
radarsh