Struts2-Shang xuexiang Ma soldiers-learning notes

Source: Internet
Author: User

Learn With your mind

Struts tag definition taglib

 

<%@taglib uri=/struts-tags prefix=s%>

 

Set the Development Mode devmode in Struts. xml

 

 

 

Set the default encoding in Struts. xml

 

 

 

The Struts. xml file contains other modules.

 

 

 

Mark error in Action

 

this.addFieldError(error_name,The Name Is Not Equals To qsuron);return ERROR;

Set Default Action in Struct. xml

 

 

 

Retrieve error messages in Jsp

 

 
  
 

 

You can also use debug to view
 

Result type

 

1. dispatcher server jump (URL unchanged) 2. redirect of the redirect client (URL change, and request a new page) 3. chain jump to action4.redirectAction can jump to action5.freemaker a framework 6. httpheader HTTP header information 7. stream upload and download 8. xslt and XML-related modifiers 9. plaintext returns the source code (with <%, which may be used for tutorial websites) 10. title dynamically update the webpage title

 

 

 
  
   
  
                       
    
     /ActionIntroduction.jsp
                                
    
     /r1.jsp
                                
    
     /r2.jsp
                                
    
     r1
                                
    
     r2
            
   
      
 

Frequently Asked Questions: when the other actions to chain are in another namespace, the Code is as follows:

 

        
 
  dashboard
  /secure        
     


 


 

 

 

Operation client request, session, application-method 1 in Action

 

package com.qsuron.action;import java.util.Map;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class LoginAction1 extends ActionSupport{private static final long serialVersionUID = 1L;private Map request;private Map session;private Map application;@SuppressWarnings(unchecked)public LoginAction1(){request = (Map
 
  ) ActionContext.getContext().get(request);session = ActionContext.getContext().getSession();application = ActionContext.getContext().getApplication();}public String login(){request.put(r1,request-qsuron);session.put(s1,session-qsuron);application.put(a1,application-qsuron);return SUCCESS;}}
 

Actions in the client request, session, application-method 2-the most common

 

Package com. qsuron. action; import java. util. map; import org. apache. struts2.interceptor. applicationAware; import org. apache. struts2.interceptor. requestAware; import org. apache. struts2.interceptor. sessionAware; import com. opensymphony. xwork2.ActionContext; import com. opensymphony. xwork2.ActionSupport;/** the most common * Reflects DI (dependcy injection) or IoC (inverse of control) design idea * similar to DomainModelParamInput */public class LoginAction2 extends ActionSupport implements RequestAware, SessionAware, applicationAware {private static final long serialVersionUID = 1L; private Map
 
  
Request; private Map
  
   
Session; private Map
   
    
Application; public String login () {System. out. println (1, 222); request. put (r1, request-qsuron); session. put (s1, session-qsuron); application. put (a1, application-qsuron); return SUCCESS;} public void setRequest (Map
    
     
Request) {this. request = request;} public void setSession (Map
     
      
Session) {this. session = session;} public void setApplication (Map
      
        Application) {this. application = application ;}}
      
     
    
   
  
 

 

In Action, the client request, session, and application-method 3
package com.qsuron.action;import java.util.Map;import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpSession;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class LoginAction3 extends ActionSupport{private static final long serialVersionUID = 1L;private HttpServletRequest request;private HttpSession session;private ServletContext application;public LoginAction3(){request = ServletActionContext.getRequest();session = request.getSession();application = session.getServletContext();}public String login(){System.out.println(333);request.setAttribute(r1,request-qsuron);session.setAttribute(s1,session-qsuron);application.setAttribute(a1,application-qsuron);return SUCCESS;}}
Operation client request, session, application-Method 4 in Action

 

 

package com.qsuron.action;import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpSession;import org.apache.struts2.interceptor.ServletRequestAware;import com.opensymphony.xwork2.ActionSupport;public class LoginAction4 extends ActionSupport implements ServletRequestAware{private static final long serialVersionUID = 1L;private HttpServletRequest request;private HttpSession session;private ServletContext application;public String login(){System.out.println(444);request.setAttribute(r1,request-qsuron);session.setAttribute(s1,session-qsuron);application.setAttribute(a1,application-qsuron);return SUCCESS;}public void setServletRequest(HttpServletRequest request) {this.request = request;this.session = request.getSession();this.application = session.getServletContext();}}

 

The client uses the Struts2 or Jsp statement to take values for the request, session, and application in the action.

 

 
  <%=request.getAttribute(r1) %>
 

 

 

 


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.