Java/JSP/Form Hidden Field
Версия от 18:01, 31 мая 2010; (обсуждение)
Reading Hidden Controls
<HTML>
<HEAD>
<TITLE>Reading Hidden Controls</TITLE>
</HEAD>
<BODY>
<H1>Reading Hidden Controls</H1>
<%
String text = "";
if(request.getParameter("TEXT1") != null) {
out.println("The hidden text is:" + request.getParameter("TEXT1"));
text = request.getParameter("TEXT1");
}
%>
<FORM ACTION="action.jsp" METHOD="POST">
<INPUT TYPE="TEXT" NAME="TEXT1">
<INPUT TYPE="HIDDEN" NAME="HIDDEN"
VALUE="<%= text%>">
<INPUT TYPE="SUBMIT" VALUE="Set Hidden Text">
</FORM>
</BODY>
</HTML>
Submitting Hidden Fields
//File: index.html
<HTML>
<HEAD>
<TITLE>Submitting Hidden Fields</TITLE>
</HEAD>
<BODY>
<H1>Submitting Hidden Fields</H1>
<FORM ACTION="formAction.jsp" METHOD="POST">
<INPUT TYPE="HIDDEN" NAME="HIDDEN" VALUE="Hello from JSP!">
<INPUT TYPE="SUBMIT" VALUE="Submit">
</FORM>
</BODY>
</HTML>
//////////////////////////////////////////////////////////////////////
//File: formAction.jsp
<HTML>
<HEAD>
<TITLE>Reading Hidden Controls</TITLE>
</HEAD>
<BODY>
<H1>Reading Hidden Controls</H1>
The hidden text is:
<% out.println(request.getParameter("HIDDEN")); %>
</BODY>
</HTML>