Java/JSP/Form Select
Версия от 18:01, 31 мая 2010; (обсуждение)
Getting Parameter Names Jsp
//File: index.html
<HTML>
<HEAD>
<TITLE>Getting Parameter Names</TITLE>
</HEAD>
<BODY>
<H1>Getting Parameter Names<H1>
<FORM ACTION="formAction.jsp" METHOD="POST">
<INPUT TYPE="TEXT" NAME="text1">
<BR>
<SELECT NAME="select1" SIZE="5" MULTIPLE>
<OPTION>Option 1</OPTION>
<OPTION selected>Option 2</OPTION>
<OPTION>Option 3</OPTION>
<OPTION>Option 4</OPTION>
<OPTION>Option 5</OPTION>
</SELECT>
<BR>
<INPUT TYPE="SUBMIT" VALUE="Submit">
</FORM>
</BODY>
</HTML>
///////////////////////////////////////////////////////////
//File: formAction.jsp
<HTML>
<HEAD>
<TITLE>Reading Parameter Names</TITLE>
</HEAD>
<BODY>
<H1>Reading Parameter Names</H1>
Parameter Names:
<BR>
<% java.util.Enumeration names = request.getParameterNames();
while(names.hasMoreElements()){
out.println(names.nextElement() + "<BR>");
}
%>
</BODY>
</HTML>
Submitting Multiple Selection Select Controls
//File: index.html
<HTML>
<HEAD>
<TITLE>Submitting Multiple Selection Select Controls</TITLE>
</HEAD>
<BODY>
<H1>Submitting Multiple Selection Select Controls<H1>
<FORM ACTION="formAction.jsp" METHOD="POST">
<SELECT NAME="select1" SIZE="5" MULTIPLE>
<OPTION>Option 1</OPTION>
<OPTION SELECTED>Option 2</OPTION>
<OPTION>Option 3</OPTION>
<OPTION>Option 4</OPTION>
<OPTION>Option 5</OPTION>
</SELECT>
<BR>
<INPUT TYPE="SUBMIT" VALUE="Submit">
</FORM>
</BODY>
</HTML>
//File: formAction.jsp
<HTML>
<HEAD>
<TITLE>Reading Multiple Selection Select Controls</TITLE>
</HEAD>
<BODY>
<H1>Reading Multiple Selection Select Controls</H1>
You selected:
<BR>
<% String[] items = request.getParameterValues("select1");
for(int loopIndex = 0; loopIndex < items.length; loopIndex++){
out.println(items[loopIndex] + "<BR>");
}
%>
</BODY>
</HTML>
Submitting Select Controls
//File: index.html
<HTML>
<HEAD>
<TITLE>Submitting Select Controls</TITLE>
</HEAD>
<BODY>
<H1>Submitting Select Controls</H1>
<FORM ACTION="formAction.jsp" METHOD="POST">
<SELECT NAME="select1">
<OPTION>Option 1</OPTION>
<OPTION SELECTED>Option 2</OPTION>
<OPTION>Option 3</OPTION>
</SELECT>
<INPUT TYPE="submit" VALUE="Submit">
</FORM>
</BODY>
</HTML>
//File: formAction.jsp
<HTML>
<HEAD>
<TITLE>Reading Select Controls</TITLE>
</HEAD>
<BODY>
<H1>Reading Select Controls</H1>
You selected
<% out.println(request.getParameter("select1")); %>
</BODY>
</HTML>