• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

Beginner Help

Hi-
I am trying to read the value of a hidden field on my page. However, the output value is null rather than admin. Any help would be great.
Thanks-BG

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">

<%@ page import = "com.ca.portal.util.PathUtility,
                   com.ca.portal.util.i18n.Translator,
                   com.ca.portal.resources.util.Misc,
                   com.ca.portal.base.GlobalData" %>

<%@ page errorPage="errorpage.jsp" session ="false" %>

<html>
     <head>
          <meta http-equiv="pragma" content="no-cache">
          <title>MyWebBoard Login</title>
     </head>

     <body bgcolor="#ffffff">

          <form name="frmThis" method="post" action="login.jsp">
         
               <input type="hidden" name="userID" value="admin">

               UserID=: <%out.println(request.getParameter("userID"));%>

          </form>
     </body>
</html>
0
BeerGod
Asked:
BeerGod
  • 4
  • 3
  • 2
1 Solution
 
cheekycjCommented:
the hidden value must be passed to this page to display it.

if you want to display it like you have it use JavaScript as such:

    <body bgcolor="#ffffff">

         <form name="frmThis" method="post" action="login.jsp">
         
              <input type="hidden" name="userID" value="admin">

              UserID=: <script>document.write(document.frmThis.userID.value);</script>
         </form>
    </body>
</html>
0
 
BeerGodAuthor Commented:
hmm. i come from an asp background. i dont uderstand why if the html is processed server side along with the jsp why cant i ouput it server side?
0
 
cheekycjCommented:
html is not processed on the server side.  Java code is.  it outputs html and sends it to the browser.  Any HTML code is not accessible to the Java code.  This holds for Server Side ASP too.

CJ
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Jan LouwerensCommented:
String userIDParameter request.getParameter("userID");
0
 
Jan LouwerensCommented:
Oh! You can't get the results within the same page... the html form has to be submitted first. Try this:




<%@ page errorPage="errorpage.jsp" session ="false" %>

<%@ page import = "com.ca.portal.util.PathUtility,
                  com.ca.portal.util.i18n.Translator,
                  com.ca.portal.resources.util.Misc,
                  com.ca.portal.base.GlobalData" %>

<%
   String userID = null;
   String formSubmit = request.getParameter("formSubmitName"); // same as form submit element 'name' parameter
   if ((formSubmit != null) && (formSubmit.equals("formSubmitValue"))) // same as form submit element 'value' parameter
   {
      userID = request.getParameter("userID");
   }
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">

<html>
    <head>
         <meta http-equiv="pragma" content="no-cache">
         <title>MyWebBoard Login</title>
    </head>

    <body bgcolor="#ffffff">

         <form name="frmThis" method="post" action="<%= request.getRequestURI() %>">

              <input type="hidden" name="userID" value="admin">
<%
   // only print if form submitted
   if (userID != null)
   {
%>
              UserID=: <%= userID %><br>
<%
   }
%>

              <input type="submit" name="formSubmitName" value="formSubmitValue">

         </form>
    </body>
</html>
0
 
Jan LouwerensCommented:
If you want the form to call "login.jsp", you have to put the form element processing in the login.jsp file, instead of whicever file this is.
This part must be in login.jsp:

<%
  String userID = null;
  String formSubmit = request.getParameter("formSubmitName"); // same as form submit element 'name'
parameter
  if ((formSubmit != null) && (formSubmit.equals("formSubmitValue"))) // same as form submit element
'value' parameter
  {
     userID = request.getParameter("userID");
  }
%>


0
 
BeerGodAuthor Commented:
you are correct. the form must first be submitted.i recall now. thank you.
0
 
Jan LouwerensCommented:
DId you accept the correct answer??
0
 
cheekycjCommented:
Thanx for the "A". Good Luck.

CJ
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now