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?



 
prainAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

________
radarsh
0
prainAuthor Commented:
<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


0
radarshCommented:
1. You should never use such absolute urls as http://localhost:8080/UserSystems/UserLogin
2. Change all absolute URLs to relative ones. /UserLogin will do.
3. The same applies to images (images/logon_header_home.gif)
4. Make all attribute names lower case. (<FORM method="POST" action="/UserLogon" id="form1" name="form1">)
5. When you do request.getParameter("somename"), there must be some input field in your HTML Form with
   name attribute equal to somename. Input field can be either of textbox, checkbox, radio button, select list,
   text area, etc.
6. In your Form, there is no such input field. Hence the null.

________
radarsh
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

rrzCommented:
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>
0
rrzCommented:
That way your code wil work locally and remotely.
0
rrzCommented:
radarsh deseves all points.
0
prainAuthor Commented:
Fixed it. Thanks for the hints.

prain
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.