Select Tag<html:select>:
html:select Tag : HTML <select> 엘리먼트를 생성한다.
Note:
- 이 태그는 바디 태그내에 form태그 내에서만 유용하다.
- 이 태그는 2개의 모드로 운용되고 multiple속성에 따라 상태가 변한다. 적용되는 데이터 타입은 다음과 같이 쓸 수 있다.
- multiple="true" 가 선택되지 않은경우 : 속성값은 제공된 데이터 타입을 스칼라 타입으로 간주하여 그에 상응한 응답을 한다.
- multiple="true"가 선택된 경우 : 제공된 데이터의 배열에 상응하는 응답을 수행 - ActionForm 빈은 멀티플이 지정되어 있지 않은경우 스칼라 속성은 기본값으로 세팅된 값이 포함되어야 한다. 멀티플이 지정되지 않은경우 reset 메소드를 이용하면 길이가 0인 배열 속성이 지정된다.
속성 설명 :
multiple : 변경 가능한 값으로 select가 복합선택을 허용할지에 대해 렌더링 한다.
name : 이 속성은 입력 필드가 렌더링될때 미리 선택되어 있을지 지정할 수 있는 폼빈과 연관된 속성이다.
property : "property"속성은 요청 파라미터의 이름. 지정된 값으로 설정된다.
size : 한번에 표시 가능한 옵션의 개수
value : 먼저 셀렉트되어 있을 옵션을 지정할 수 있다.
Example code
폼빈 클래스 생성 :SelectTagActionForm.java.
package ActionForm;
import! java.util.List;
import! javax.servlet.http.HttpServletRequest;
import! org.apache.struts.action.ActionErrors;
import! org.apache.struts.action.ActionMapping;
import! org.apache.struts.action.ActionMessage;
public class SelectTagActionForm extends org.apache.struts.action.ActionForm{
private String singleSelect;
public String getSingleSelect() {
return singleSelect;
}
public void setSingleSelect(String string) {
singleSelect = string;
}
public SelectTagActionForm() {
super();
}
}
액션 클래스 생성 SelectTagAction.java :
package action; import! ActionForm.SelectTagActionForm; import! java.util.ArrayList; import! java.util.List; import! javax.servlet.http.HttpServletRequest; import! javax.servlet.http.HttpServletResponse; import! org.apache.struts.action.Action; import! org.apache.struts.action.ActionForm; import! org.apache.struts.action.ActionMapping; import! org.apache.struts.action.ActionForward; public class SelectTagAction extends Action { private final static String SUCCESS = "success"; public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { if(form!=null){ SelectTagActionForm selectTagActionForm=(SelectTagActionForm)form; selectTagActionForm.getSingleSelect(); } return mapping.findForward(SUCCESS); } } |
Add the following entry in the struts-config.xml file for Form Bean.
Defining the form bean :
<form-bean name="SelectTagActionForm" type="ActionForm.SelectTagActionForm"/> |
struts-config.xml 액션 매핑 지정 :
Here, Action mapping helps to select the From Bean And the Action class etc, for specific requests.
<action input="/" name="SelectTagActionForm" path="/SelectTagAction"
scope="session" type="action.SelectTagAction"?alidate="false">
<forward name="success" path="/HtmlSelectTagOutPut.jsp"/>
</action>
Developing the HtmlSelectTag.jsp page :
<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %> <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %> <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body bgcolor="#999933"> <h3><font color="#FFFF33">HTML SELECT TAG DEMO.......</font></h3> <th align="right"><font color="#FFFF33"><b>Single Select Allowed:</b> </font> </th> <html:form action="SelectTagAction" method="POST"> <table border="2"> <tr><td> <html:select name="SelectTagActionForm" property="singleSelect" size="5"> <html:option value="0">select 0</html:option> <html:option value="1">select 1</html:option> <html:option value="2">select 2</html:option> <html:option value="3">select 3</html:option> <html:option value="4">select 4</html:option> <html:option value="5">select 5</html:option> <html:option value="6">select 6</html:option> <html:option value="7">select 7</html:option> <html:option value="8">select 8</html:option> <html:option value="9">select 9</html:option> </html:select><br/><br/> </td></tr> <tr><td> <html:submit/> </td></tr> </table> </html:form> </body> </html> |
HtmlSelectTagOutPut.jsp 페이지 생성 :
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<a href="HtmlSelectTag.jsp">Go Back......</a><br/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><font color="#FFFF33">OUT PUT</font></title>
</head>
<body bgcolor="#999933">
<h3><font color="#FFFF33">OUT PUT</font></h3>
<h3><font color=""><font color="#FFFF33">Selected Value is.......
</font>
</h3>
<bean:write name="SelectTagActionForm" property="singleSelect"/>
</body>
</html>
Add the following line in the index.jsp to call the form.
<a href="HtmlSelectTag.jsp">HtmlSelectTagDemo</a><br/> |
Building and Testing the Example :
Build, deploy and Test the application .
Open the browser and navigate to the HtmlSelectTag.jsp page.
Your browser displays the following page.
Don't select the option on the HtmlSelectTag.jsp?page, and see the output.
![]() |
Output without selecting option...
![]() |
Now select any option to the HtmlSelectTagOutPut.jsp .
![]() |
Output when selecting a option...
![]() |
Above actions displays the working of <html:select> with <html:option>tag.
'WEB_Programming > Struts' 카테고리의 다른 글
Radio Tag <html:radio>: 사용법 (0) | 2008.06.10 |
---|---|
Rewrite Tag<html:rewrite>: 사용법 (0) | 2008.06.10 |
Textarea Tag<html:textarea>: 사용법 (0) | 2008.06.10 |
Checkbox Tag <html:checkbox>: 사용법 (1) | 2008.06.10 |
Hidden Tag <html:hidden> : 사용법 (0) | 2008.06.10 |