Action tag is used to call action directly from jsp in struts2 framework.
Note:
I have already explained how to create struts2 project and folders for storing jsp file and for stroing action class file. I also explained where we configure the project.
Action tag is used to call action directly from jsp in struts2 framework.
Note:
I have already explained how to create struts2 project and folders for storing jsp file and for stroing action class file. I also explained where we configure the project.
Procedure:
Step 1:
Create Project name as ActionTag
Step 2:
Create Action class HelloWorld
package example;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorld extends ActionSupport
{
String greetings = null;
public String execute() throws Exception
{
setGreetings("Hello World");
return SUCCESS;
}
public String getGreetings()
{
return greetings;
}
public void setGreetings(String greetings)
{
this.greetings = greetings;
}
}
Step 3:
Create index.jsp file
< %@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"% >
< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" http://www.w3.org/TR/html4/loose.dtd >
< %@ taglib prefix="s" uri="/struts-tags" % >
< html >
< head >
< meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" >
< meta content="keyword" name="struts2 action tag example" >
< title > Struts 2 Example < /title >
< /head >
< body >
< s:action name="HelloWorldAction" executeResult="true" > < /s:action >
< /body >
< /html >
Step 4:
Create HelloWorld.jsp
< %@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"% >
< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" http://www.w3.org/TR/html4/loose.dtd >
< %@ taglib prefix="s" uri="/struts-tags" % >
< html >
< head >
< meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" >
< meta content="keyword" name="struts2 action tag example" >
< title > Struts 2 Example < /title >
< /head >
< body >
To understand how to create checkboxlist and select tag in struts2 using list property in < s:checkboxlist list=” ” > and < s:select list=” “ > .
The checkboxlist tag is UI tag. It is used to create series of checkboxes from a list
We will understand the checkboxlist and select tags from following coding.
Requirement:
Jsp files
a). home.jsp
b). checklist.jsp
c). result.jsp
Action files
a). CheckAction.java
configuration files
struts.xml
Directory structure of this project.
Note:
You have already known how to create Project for Struts2 such as SureshS.
Procedure:
Step 1:
Create home.jsp
Coding for home.jsp
< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< title > Home Page < /title >
< /head >
< body >
< s:form action="check" >
< s:submit/ >
< /s:form >
< /body >
< /html >
Step 2:
Create checklist.jsp
Coding for checklist.jsp
< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< meta name="keywords" content="example for checkboxlist, select " >
< title > CheckboxList Page < /title >
< /head >
< body >
< result name="success" > /example/result.jsp < /result >
< /action >
< /package >
< /struts >
Step 6:
Run home.jsp
In home.jsp, the button will display. You click on the button, the control will go to checklist.jsp, where you select color from checkboxlist and select country from select tag. And click button the result.jsp will display. Where the selected colors and selected country will display.
You run home.jsp
You will get like below
click Submit
where you may select any if you select RED and Green from checkboxlist
To understand how to create checkboxlist and select tag in struts2 using list property in < s:checkboxlist list=” ” > and < s:select list=” “ > .
The checkboxlist tag is UI tag. It is used to create series of checkboxes from a list
We will understand the checkboxlist and select tags from following coding.
Requirement:
Jsp files
a). home.jsp
b). checklist.jsp
c). result.jsp
Action files
a). CheckAction.java
configuration files
struts.xml
Directory structure of this project.
Note:
You have already known how to create Project for Struts2 such as SureshS.