OGNL expression struts2

Source: Internet
Author: User

OGNL expression struts2

Package com. cola. action; import java. util. arrayList; import java. util. hashMap; import java. util. list; import java. util. map; import javax. servlet. http. httpServletRequest; import org. apache. struts2.ServletActionContext; import com. cola. bean. user; import com. opensymphony. xwork2.ActionContext; import com. opensymphony. xwork2.ActionSupport;/*** @ Note: jsp <-------> Action: use the set [A --> J] get [J --> A] method to pass the object to the page. Struts2 * tag and OGNL expression web object does not need setget method jsp page value = "# session. [Key name of the key-value pair] "jing */@ SuppressWarnings (" all ") public class OGNLAction extends ActionSupport {private User stu = new User (); // pass the object private User techer = new User (); private User user = new User (); private List <User> list = new ArrayList <User> (); // pass the List private Map session; // The private Map request is retrieved through ActionContext in the sruts encapsulation; // by s Ruts encapsulate the retrieval of private HttpServletRequest httprequest through ActionContext; // use private Map <String, String> map = new HashMap <String, String> (); public OGNLAction () for Embedded web objects () {// obtain the session to prevent the session from being cleared every time the execute () method in the current Action is loaded. The session = ActionContext is put into the constructor. getContext (). getSession (); // get the request ActionContext. getContext. get () returns Object request = (Map) ActionContext. getContext (). get ("request"); // get htt Prequest httprequest = ServletActionContext. getRequest () ;}@ Override public String execute () throws Exception {// TODO Auto-generated method stub System. out. println ("***************************"); user. setUsername ("James"); user. setPassword ("admin"); stu. setUsername ("xiaoming"); stu. setPassword ("123"); techer. setUsername ("zhang"); techer. setPassword ("123"); list. add (user); list. add (stu); list. ad D (techer); // Add the value to the session. The session type is Map session. put ("sesskey", "fool"); request. put ("reqkey", "toofool"); httprequest. setAttribute ("httpreqkey", "clever"); // map key can be repeated. put ("1", "hello"); map. put ("2", "hello"); map. put ("3", "hello"); return SUCCESS;} public Map <String, String> getMap () {return map;} public void setMap (Map <String, string> map) {this. map = map;} public List <User> getList () {Return list;} public User getUser () {return user;} public void setList (List <User> list) {this. list = list;} public void setUser (User user User) {this. user = user;} public String show () {// pass the return "this is show () of function in the Action! ";}}< % @ Page language =" java "contentType =" text/html; charset = UTF-8 "pageEncoding =" UTF-8 "%> <% @ taglib uri ="/struts-tags "prefix =" s "%> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd"> 

 

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.