
Offers help to ajax approval. In such case, page won't be invigorated or reloaded so it will make the execution quick. It is verifiable done utilizing javascript i.e. utilized for the customer side approval.
Steps to perform AJAX
- create the form to get input from the user
- Inherit the ActionSupport class in your action
- Define the validation in validation.xml file
- Define result name input for the error message and register the jsonValidationWorkflowStack in struts.xml file
The AJAX approval is performed by jsonValidation interceptor. It is not found in the default stack so we have to characterize it unequivocally. It doesn't play out any approval itself that is the reason it must be utilized with approval interceptor. It is found in the jsonValidationWorkflowStack, that incorporates jsonValidation, approval and work process interceptors and basicstack.
Aware Interfaces:Struts 2 Aware interfaces are utilized to place data into the demand, reaction, setting or session question.The activity class must execute these interfaces to store data with the goal that it can be recovered from other activity classThe four aware interfaces are:- org.apache.struts2.interceptor.SessionAware
- org.apache.struts2.util.ServletContextAware
- org.apache.struts2.interceptor.ServletRequestAware
- org.apache.struts2.interceptor.ServletResponseAware
Methods
- public static HttpServletRequest getRequest()
- public static HttpServletResponse getResponse()
- public static ServletContext getServletContext
The struts 2 system passes the case of org.apache.struts2.dispatcher.SessionMap.It expands the java.util.AbstractMap class which executes the java.util.Map.SessionMap. There are numerous helpful techniques for SessionMap class.
Methods of SessionMap class
Methods |
public Object put(Object key, Object value) |
public Object remove(Object key) |
public Object get(Object key) |
public Set entrySet() |
public void invalidate() |
public void clear() |
The i18n interceptor gives multi-lingual help to your application. It handles setting region for the activity. It can be utilized if client needs to set his/her region and get information as indicated by the region gave. It is found in the defaultStack bydefault, so you don't need to determine it expressly.
Parameters of i18n interceptor:
There are 2 parameters defined for i18n interceptor. Both are optional.Parameter | Description |
parameterName | It specifies the name of the HTTP request parameter.It is set to request_locale bydefault. |
attributeName | specifies the name of the session key to store the locale.It is WW_TRANS_I18N_LOCALE bydefault. |
- Login.java
- Login_en.properties and Login_hi.properties
- struts.xml
- index.jsp
- login-success.jsp
1) Create the action class
Login.java:package com.javaspot;import com.opensymphony.xwork2.ActionSupport;public class Login extends ActionSupport{private String name;public String getName() {return name;}public void setName(String name) {this.name = name;}public String execute(){return SUCCESS;}}2) Create properties files Login_en.propertieslogin.msg=Good Morning! Login_hi.propertieslogin.msg=Suprabhat!3) Create index.jsp for input index.jsp<%@ taglib prefix="s" uri="/struts-tags" %><s:form action="login"><s:textfield name="name" label="Name">s:textfield><s:submit>s:submit>s:form>struts.xml:
xml version="1.0" encoding="UTF-8" ?>><struts><package name="abc" extends="struts-default" ><action name="login" class="com.javaspot.Login" method="execute"><result name="success">/login-success.jsp4) Create view component login-success.jsp<%@ taglib uri="/struts-tags" prefix="s" %>Welcome,Message is:
- By convention
- By annotation
- Create input page (optional)
- Create the action class
- Create view components
create zero configuration file by convention.
In this example, index.jsp- LoginAction.java
- login-success.jsp
- login-error.jsp