Struts 2 UI Tags are straightforward and simple to utilize. You require not compose any HTML code, the UI labels will consequently produce them for you in view of the subject you select. As a matter of course the HTML topic is utilized. The HTML subject uses tables to position the shape components.
In this case you will perceive how to make an enrollment page utilizing Struts 2 UI labels. You will likewise figure out how to prepopulate the shape fields, set default esteems to it and to retrieve the qualities back in the jsp page.
DateTimePicker Example1)Create index.jsp for input:This jsp page makes a frame utilizing struts UI labels. It gets name, watchword and email id from the client. index.jsp<%@ taglib prefix="s" uri="/struts-tags" %><%@ taglib prefix="sx" uri="/struts-dojo-tags" %>JAVA Tutorial Video
[embed]https://www.youtube.com/watch?v=Mb8nG-NH6gg&t=2835s[/embed]2) Create the action classThis activity class acquires the ActionSupport class and overrides the execute strategy. RegisterAction.java:package mypack;import com.opensymphony.xwork2.ActionSupport;import java.util.Date;public class DateBean extends ActionSupport {private Date todayDate,todayDate2;public Date getTodayDate2() {return todayDate2;}public void setTodayDate2(Date todayDate2) {this.todayDate2 = todayDate2;}public Date getTodayDate() {return todayDate;}public void setTodayDate(Date value) {todayDate = value;}public String execute(){return SUCCESS;}} 3)Create struts.xmlThis xml document characterizes an additional outcome by the name input, and an interceptor jsonValidatorWorkflowStack.struts.xml version="1.0" encoding="UTF-8" ?>>Struts 2 Iterator tag is used to accentuate over an value which can be any of java.util.Collection or java.util.Iterator. In these instructional activities, you will make an once-over factor, use Iterator tag to circle over it and get the iterator status with IteratorStatus.
1)Create index.jsp for input index.jspfindPartner2)Create the action classFind.javapackage mypack;import java.util.ArrayList;public class Find {private ArrayList list=new ArrayList();public ArrayList getList() {return list;}public void setList(ArrayList list) {this.list = list;}public String execute(){User u1=new User();u1.setUserName("Amit");u1.setUserPass("kumar");u1.setEmail("amit@gmail.com");User u2=new User();u2.setUserName("Vijay");u2.setUserPass("kumar");u2.setEmail("vijay@gmail.com");list.add(u1);list.add(u2);return "success";}}3)Create the modelUser.javapackage mypack;public class User {private String userName,userPass,email;public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getUserPass() {return userPass;}public void setUserPass(String userPass) {this.userPass = userPass;}public String getEmail() {return email;}public void setEmail(String email) {this.email = email;}}4) Create struts.xmlstruts.xmlIn this case, we will make an enrollment registration utilizing struts UI labels and store these data into the prophet database. You may utilize other database likewise, for example, mysql, DB2 and so forth as per your necessity. We see the table first that we have to make in the prophet database.
CREATE TABLE "STRUTSUSER"( "NAME" VARCHAR2(4000),"PASSWORD" VARCHAR2(4000),"EMAIL" VARCHAR2(4000),"GENDER" VARCHAR2(4000),"COUNTRY" VARCHAR2(4000))/1)Create input page (index.jsp)index.jsp<%@ taglib uri="/struts-tags" prefix="s" %>Login and Logout:
Before making the login and logout application utilizing struts 2, you should clear the ideas of aware interfaces in struts 2. In this illustration, we have utilized the SessionAware interface to put the data in the session extension and ServletActionContext class to get the data from the session scope.
This illustration contains three connections login, logout and profile. The end client can't tap on the profile page until he/she is signed in. Subsequent to getting signed in, he/she may go the profile page. On the off chance that the end client taps on the logout page, he won't have the capacity to get to the profile page.
CREATE TABLE "USER3333"( "ID" NUMBER,"NAME" VARCHAR2(4000),"PASSWORD" VARCHAR2(4000),"EMAIL" VARCHAR2(4000),CONSTRAINT "USER3333_PK" PRIMARY KEY ("ID") ENABLE ) /Fetching all records:To get every one of the records, we have put away every one of the records in an accumulation (utilizing List), and showing the information of the gathering utilizing the iterator tag of struts2.
Here, we expect that you have a table in oracle database named user3333 that contains records. The table query is
CREATE TABLE "USER3333"( "ID" NUMBER,"NAME" VARCHAR2(4000),"PASSWORD" VARCHAR2(4000),"EMAIL" VARCHAR2(4000),CONSTRAINT "USER3333_PK" PRIMARY KEY ("ID") ENABLE ) /To fetch all the records of the table- index.jsp
- Register.java
- User.java
- struts.xml
- welcome.jsp