jspFrom question

Posted on 2006-03-20
Last Modified: 2010-04-01
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?

Question by:prain
    LVL 10

    Expert Comment

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


    Author Comment



    <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;
    <FORM Method="POST"
          Action="http://localhost:8080/UserSystems/UserLogin" ID="form1" Name="form1">

    <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">
      <TD> User ID:</TD>
      <TD><INPUT Type="text" Name="UserID" Size="12" MaxLength="20"></TD>
      <TD> Password:</TD>
      <TD><INPUT Type="password" Name="PassWord" size="12" maxlength="20"></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>
     <!-- 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  -->
     <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 -->

     <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


     <SCRIPT language="javascript">

    and the 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);
       {  // unsuccessful
       System.out.println("Pass Word Unsuccessful");
          session.setAttribute ("isDemoLogin", "No");
          session.setAttribute ("UserID", "");
          invalidID = true;
          doGet (req, res);
    } // end of doPost() method

    LVL 10

    Accepted Solution

    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.

    LVL 27

    Expert Comment

    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>
    <div><img src="/UserSystems/images/footer.gif" ></div>
    LVL 27

    Expert Comment

    That way your code wil work locally and remotely.
    LVL 27

    Expert Comment

    radarsh deseves all points.

    Author Comment

    Fixed it. Thanks for the hints.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Suggested Solutions

    ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
    For Sennheiser, comfort, quality and security are high priority areas. This paper addresses the security of Bluetooth technology and the supplementary security that Sennheiser’s Contact Center and Office (CC&O) headsets provide.  
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now