How to Return a Hidden Field in JSP

Java ServerPages give Java programmers a way to embed Java functionality into their Web design. JSPs allow programmers to perform normal programming functions, such as mathematical calculation, branching statements and method calls on an existing Java server while integrating with HTML. For example, you can create a hidden field in HTML, which does not display to the user but stores information about the form session, and use it in a JSP page.

Instructions

    • 1

      Create a hidden field in your HTML form:

      <html>
      <form action="action.jsp" method="POST">
      <input type="HIDDEN" name="HIDDEN" value="This is a hidden field!">
      <input type="SUBMIT" value="Submit">
      </form>
      </html>

    • 2

      Create a JSP page names "action.jsp" to manipulate the form data:

      <html>
      <body>

      <% out.println(request.getParameter("HIDDEN")); %>

      </html>
      </body>

    • 3

      Create a function inside the JSP code to return the hidden value:

      <html>
      <body>

      <% out.println(request.getParameter("HIDDEN"));

      String returnHidden(String h){
      return h;
      }

      String h = returnHidden(request.getParameter("HIDDEN"));

      %>

      </html>
      </body>

Related Searches:

References

Comments

Related Ads

Featured