본문 바로가기

WEB_Programming/Struts

Radio Tag <html:radio>: 사용법

Radio Tag <html:radio>:

html:radio 태그 - HTML <input>엘리먼트중 radio를 지정한다. 현재 폼에 연결된 빈 속성에 따라 값이 지정된다.

Note : 이 태그는 body내의 폼태그에 내포된 경우에만 그 값이 반영된다. 


 속성 설명 :

disabled   : 필드를 disable하려면 true를 설정하면 된다.

name        : 빈 속성이름, 입력 필드의 현재값에 어떻 프로퍼티로 랜더링 할지 결정한다. 폼태그에 연관된 빈이 지정되지 않은경우 내부적으로 내포된 값으로 이용한다.

property    : 라디오 태그에 상응하는 빈 프로퍼티.

value        : 라디오 태그 값


Example code :
폼빈 작성 : RadioTagActionForm.java

 package ActionForm;

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 RadioTagActionForm extends 

org.apache.struts.action.ActionForm{

     
   
    private String indian;
   
    private String american;
   
    public String getIndian() {
        return indian;
    }
   
    public void setIndian(String string) {
        indian = string;
    }
    public String getAmerican() {
        return american;
    }
   
    public void setAmerican(String string) {
        american = string;
    }
   
    public RadioTagActionForm() {
        super();
       
    }

}


Action Class 작성 :
RadioTagAction .java.

 package action;

import! ActionForm.RadioTagActionForm;
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 RadioTagAction extends Action {
       
 private final static String SUCCESS = "success";
       
 public ActionForward execute(ActionMapping mapping, ActionForm  form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
               
      if(form!=null){
               
 RadioTagActionForm radiaTagActionForm=(RadioTagActionForm)form;
 System.out.println("radiaTagActionForm"

+radiaTagActionForm.getAmerican
());
     }        
      return mapping.findForward(SUCCESS);
       
    }
}


struts-config.xml 파일에 폼 빈 적용 :
Add the following entry in the struts-config.xml file for defining the form bean .

 <form-bean name="RadioTagActionForm" type="ActionForm.RadioTagActionForm"/>

 

struts-config.xml 에 액션 매핑 적용 :

 <action input="/" name="RadioTagActionForm" path="/RadioTagAction"
    
scope="request" type="action.RadioTagAction" validate="false">

<forward name="success" path="/redioTagOutPut.jsp"/>?/font>

</action>

 

Developing the RadioTag.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>RadioTag</title>
        <font color="#FFFF33">Plz select Option for Demo  ---></font>s
    </head>
     <body bgcolor="#999933">      
        <h3><font color="#FFFF33">RadioTag</font></h3>        
        <html:form action="/RadioTagAction">            
            <h3>Indian</h3><html:radio name=
"RadioTagActionForm"
                      
property="indian" value="Indian"  disabled="false"/>
            <h3>American</h3><html:radio name="RadioTagActionForm"

                      property=
"american" value="American" disabled="false"/>
            <html:submit/>
        </html:form>
       
    </body>
</html>

redioTagOutPut.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>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><font color="#FFFF33">OUT PUT</font></title>
    </head>
     <a href="RadioTag.jsp">Go Back.........</a><br/>  
    <body bgcolor="#999933">
       
        <h3><font color="#FFFF33">OUT PUT</font></h3>  
        <h3><font color="#FFFF33">Selected Value is.......</font></h3>
        <bean:write name="RadioTagActionForm" property="indian"/>
        <bean:write name="RadioTagActionForm" property="american"/>
       
    </body>
</html>

Add the following line in the index.jsp to call the form.

 <a href="RadioTag.jsp">RadioTagDemo</a><br/>

Building and Testing the Example  :
Build and deploy and Test  the application . Open the browser and navigate to the RadioTag.jsp page.
Your browser displays the following page.

Don't select  option  on the RadioTag.jsp page, and see the output.

 

Output:

 

Now select the option on  the RadioTag.jsp ,

 

Output:

Above demo  Displays the working of<html:radio>tag.