struts2_day03_10_从值栈获取字符串_11_从值栈获取对象

来源:互联网 发布:tensorflow gpu 编辑:程序博客网 时间:2024/06/05 16:05

10_从值栈获取字符串


从值栈获取数据

1 使用struts2的标签+ognl表达式获取值栈数据

1<s:property value=”ognl表达式”/>

 

获取字符串

1 向值栈放字符串

 

2 jsp使用struts2标签+ognl表达式获取



com.hlg.valuestack.ValueStackAction

package com.hlg.valuestack;import com.opensymphony.xwork2.ActionSupport;public class ValueStackAction extends ActionSupport {private String username;public String getUsername() {return username;}public String execute(){username = "获取字符串";return "success";}}

<action name="valueStack" class="com.hlg.valuestack.ValueStackAction"><result name="success">/valueStack.jsp</result></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"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><s:debug></s:debug><s:property value="username"/></body></html>



----------------------------------------------------------------------------------------------------------

11_从值栈获取对象

获取对象

1 向值栈放对象

package com.hlg.valuestack;import com.hlg.entity.User;import com.opensymphony.xwork2.ActionSupport;public class ValueStackAction extends ActionSupport {//private String username;private User user = new User();public User getUser() {return user;}//public String getUsername() {//return username;//}public String execute(){//username = "获取字符串";user.setUsername("乔峰");user.setPassword("111");user.setAddress("丐帮");return "success";}}


2 在页面中获取值


<%@ 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"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><s:debug></s:debug><s:property value="username"/>获取对象的值:<br><s:property value="user.username"/><br><s:property value="user.password"/><br><s:property value="user.address"/><br></body></html>


原创粉丝点击