Link to home
Create AccountLog in
Avatar of prain
prainFlag for United States of America

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("fromJSP : " + 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?



 
Avatar of radarsh
radarsh

How are you passing parameters from your JSP? Could you post your JSP code?

________
radarsh
Avatar of prain

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(document.logonform.usr_name, document.logonform.usr_password.value, document.logonform.remember.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.focus()
 //-->
 </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("passWord : " + passWord);
 System.out.println("fromJSP : " + 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


ASKER CERTIFIED SOLUTION
Avatar of radarsh
radarsh

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of rrz
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/footer.gif" ></div>
That way your code wil work locally and remotely.
radarsh deseves all points.
Avatar of prain

ASKER

Fixed it. Thanks for the hints.

prain