[Last Call] Learn how to a build a cloud-first strategyRegister Now


jspFrom question

Posted on 2006-03-20
Medium Priority
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
  • 3
  • 2
  • 2
LVL 10

Expert Comment

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


Author Comment

ID: 16239005


<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 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);
   {  // 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

radarsh earned 200 total points
ID: 16239162
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.

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 28

Expert Comment

ID: 16239194
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 28

Expert Comment

ID: 16239345
That way your code wil work locally and remotely.
LVL 28

Expert Comment

ID: 16239487
radarsh deseves all points.

Author Comment

ID: 16240483
Fixed it. Thanks for the hints.


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Currently, there is an issue with being able to copy values from an external application to a dropdown list in Project Web Access (PWA).  The standard copy and paste methods don't seem to work properly. Here is a way to accomplish this task to s…
Tech giants such as Amazon and Google have sold Alexa and Echo to such an extent that they have become household names. And soon they are expected to be used by commoners in their homes, ordering takeout, picking out a song, answering trivia questio…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

831 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