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" %> <html> <head><title>Struts2.2.1_ChexkBox_Tag_Example</title></head> <body> <h2>Struts2.2.1_ChexkBox_Tag_Example</h2><hr /> <h2>Select value of check box</h2> <s:form action="checkbox.action"> <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> <s:submit name="submit" value="Submit" /> </s:form></body> </html> |
2-CheckBoxAction .java
package roseindia; import com.opensymphony.xwork2.ActionSupport; public class CheckBoxAction extends ActionSupport{ private boolean hello; private boolean hi; private boolean gm; public String execute() throws Exception { return SUCCESS; } public boolean isHello() { return hello; } public void setHello(boolean hello) { this.hello = hello; } public boolean isHi() { return hi; } public void setHi(boolean hi) { this.hi = hi; } public boolean isGm() { return gm; } public void setGm(boolean gm) { this.gm = gm; } } |
3_struts.xml
<struts> <package name="roseindia" extends="struts-default" namespace="/" > <action name="checkbox" class="roseindia.CheckBoxAction"> <result name="success">/jsp/checkboxView.jsp</result> </action> </package></struts> |
5_checkboxView.jsp
<%@ taglib uri="/struts-tags" prefix="s" %> <html> <head><title>Struts2.2.1_ChexkBox_Tag_Example</title> <style type="text/css"> p {color: gray;}</style> </head> <body> <h2>Struts2.2.1_ChexkBox_Tag_Example</h2><hr/> <h2>value of check box</h2><p> Hello : <s:property value="hello"/><br/> Hi : <s:property value="hi"/><br/> GoodMorning : <s:property value="gm"/><br/></p> </body> </html> |
indexJsp.gif
selectBox.gif
Output.gif
Advertisements
Ads
Ads