Struts2.2.1 checkbox tag example.
Posted on: January 10, 2011 at 12:00 AM
In this tutorial, you will see the example of Struts2.2.1 checkbox tag.

Struts2.2.1 checkbox tag example.

In this example, you will see the use of checkbox tag of struts2.2.1 framework. The checkbox tag is a UI tag that is used to render an HTML input element of type checkbox, populated by the specified property from the ValueStack. 

Directory structure of checkbox tag example.

 1- index.jsp  

<%@ taglib uri="/struts-tags" prefix="s" %>ADS_TO_REPLACE_1

<html>

<head><title>Struts2.2.1_ChexkBox_Tag_Example</title></head>

<body>ADS_TO_REPLACE_2

<h2>Struts2.2.1_ChexkBox_Tag_Example</h2><hr />

<h2>Select value of check box</h2>

<s:form action="checkbox.action">ADS_TO_REPLACE_3

<s:checkbox name="hello" label="Hello" value="true"> </s:checkbox>

<s:checkbox name="hi" label="Hi"> </s:checkbox>

<s:checkbox name="gm" label="GoodMorning"> </s:checkbox>ADS_TO_REPLACE_4

<s:submit name="submit" value="Submit" />

</s:form></body>

</html>

2-CheckBoxAction .java ADS_TO_REPLACE_5

package roseindia;

import com.opensymphony.xwork2.ActionSupport;

public class CheckBoxAction extends ActionSupport{ADS_TO_REPLACE_6

private boolean hello;

private boolean hi;

private boolean gm;ADS_TO_REPLACE_7

public String execute() throws Exception {

return SUCCESS;

}ADS_TO_REPLACE_8

public boolean isHello() {

return hello;

}ADS_TO_REPLACE_9

public void setHello(boolean hello) {

this.hello = hello;

}ADS_TO_REPLACE_10

public boolean isHi() {

return hi;

}ADS_TO_REPLACE_11

public void setHi(boolean hi) {

this.hi = hi;

}ADS_TO_REPLACE_12

public boolean isGm() {

return gm;

}ADS_TO_REPLACE_13

public void setGm(boolean gm) {

this.gm = gm;

}ADS_TO_REPLACE_14

}

3_struts.xml

<struts>

<package name="roseindia" extends="struts-default" namespace="/" >

<action name="checkbox" class="roseindia.CheckBoxAction">ADS_TO_REPLACE_15

<result name="success">/jsp/checkboxView.jsp</result>

</action>

</package>ADS_TO_REPLACE_16

</struts>

5_checkboxView.jsp

<%@ taglib uri="/struts-tags" prefix="s" %>

<html>

<head><title>Struts2.2.1_ChexkBox_Tag_Example</title>ADS_TO_REPLACE_17

<style type="text/css">

p {color: gray;}</style>

</head>ADS_TO_REPLACE_18

<body>

<h2>Struts2.2.1_ChexkBox_Tag_Example</h2><hr/>

<h2>value of check box</h2><p>ADS_TO_REPLACE_19

Hello : <s:property value="hello"/><br/>

Hi : <s:property value="hi"/><br/>

GoodMorning : <s:property value="gm"/><br/></p>ADS_TO_REPLACE_20

</body>

</html>

 

indexJsp.gif

ADS_TO_REPLACE_21

selectBox.gif

Output.gifADS_TO_REPLACE_22

Download Select Source Code


Related Tags for Struts2.2.1 checkbox tag example.:

Advertisements

Ads

 
Advertisement null

Ads