Struts 2 <s:checkbox> checkbox example

Struts 2 <s:checkbox> checkbox example

Previous Home Next

 

The Struts 2.0 framework provide checkbox to select item in the list through the<s:checkbox></s:checkbox> tag. 
This tag provide the facility to get element in the list .
The Struts 2 checkbox component provide the following <s:checkbox></s:checkbox> tag:

<s:checkbox name="checkMe" fieldValue="true" label="Check Me"/>


 
Directory Structure of <s:checkbox> tag Example in Struts 2.0 Using MyEclipse IDE



index.jsp

<%@taglib uri="/struts-tags" prefix="s"%>
<h2>Check Box Example in Struts2 Framework</h2>
<s:form action="check">
<s:checkbox name="checkMe" fieldValue="true" label="Check Me"/>
<s:submit value="Submit"></s:submit>
</s:form>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  
  <filter>
  <filter-name>f1</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>
  <filter-mapping>
  <filter-name>f1</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration
2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="demo" extends="struts-default">
<action name="check" class="org.r4r.CheckBoxAction">
<result name="success">/success.jsp</result>
</action>
</package>
</struts> 

CheckBoxAction.java

package org.r4r;

public class CheckBoxAction {
	private String checkMe;
	
	public String execute(){
		return "success";
	}

	public String getCheckMe() {
		return checkMe;
	}

	public void setCheckMe(String checkMe) {
		this.checkMe = checkMe;
	}
	

}

hello.jsp

<%@taglib uri="/struts-tags" prefix="s"%>
<h2>Check Box Example in Struts2 Framework</h2>
Check Me through CheckBox :-<s:property value="checkMe"/>

Output






Previous Home Next