Struts值栈与Ognl

2024-02-01 10:32
文章标签 struts ognl 值栈

本文主要是介绍Struts值栈与Ognl,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

配置xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd">
<struts><package name="stack" namespace="/stack" extends="struts-default"><action name="stack_*" class="star.july.c_valuestack.StackAction" method="{1}"><result name="success">/index.jsp</result><result name="input">/add.jsp</result></action></package></struts>


StackAction:   

package star.july.c_valuestack;
import java.util.Map;
import star.july.b_validation.Student;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.util.ValueStack;
public class StackAction extends ActionSupport{Student student;public Student getStudent() {return student;}public void setStudent(Student student) {this.student = student;}public String stack(){String name = student.getName();ActionContext ac = ActionContext.getContext();//使用对象栈存储对象//获取值栈,用list的栈方式存取ValueStack vs = ac.getValueStack();//将对象放入栈中,压栈vs.push(student);//弹栈//       vs.pop();//使用映射栈存取对象//添加自己的值和栈Map map = ac.getContextMap();map.put("map", "自定义");//获取requestMap rp = (Map)ac.get("request");rp.put("rp", "请求");//获取sessionMap sp = ac.getSession();sp.put("sp", "会话");//获取application并赋值Map ap = ac.getApplication();ap.put("ap", "应用");System.out.println(student);return SUCCESS;}
}


输入值:

 <body><s:fielderror></s:fielderror><form action="<c:url value='/stack/stack_stack'/>" method="post">用户名:<input type="text" name="student.name"><br><input type="submit" value="提交"/></form>



<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"  %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>My JSP 'index.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">   <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><!-- 对象栈的取方式,用[] --><!-- 取出方式,从下表开始一直取到结束为止 -->对象栈的取方式,用[]<s:property value="[1]"/><br><s:property value="[0]"/><br><br><br><!-- 映射栈的取值方式,前面加# -->映射栈的取值方式,前面加#<br><s:property value="#map"/><br><s:property value="#request.rp"/><br><s:property value="#session.sp"/><br><s:property value="#application.ap"/><!-- 调试值栈,看值 --><s:debug></s:debug></body>
</html>


这篇关于Struts值栈与Ognl的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/666993

相关文章

Thymeleaf:生成静态文件及异常处理java.lang.NoClassDefFoundError: ognl/PropertyAccessor

我们需要引入包: <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><dependency><groupId>org.springframework</groupId><artifactId>sp

在struts.xml中,如何配置请求转发和请求重定向!

<span style="font-size:18px;"><span style="white-space:pre"> </span><!--<strong>下面用请求转发action </strong>,<strong>这样过去id不会丢</strong>,如果用重定向的话,id会丢 --><result name="updatePopedom"<span style="color:#ff00

修改struts中:fielderror.ftl 模板

在项目登录页面: 当验证码输入有误时,应该提示:验证码输入有误,请重新输入 ,但是页面出现乱了! 错误原因: 在产生错误信息时,页面中增加了<ul> <li><span></span></li></ul>标签,该如何修改改, 解决方法(一): 在项目的src下,新建文件夹:template.simple,在文件夹里面放修改好的fielderror.ftl文件。 fi

Struts 2的工作流程

基本简要流程如下:1、客户端浏览器发出HTTP请求。2、根据web.xml配置,该请求被 FilterDispatcher接收。3、根据struts.xml配置,找到需要调用的Action类和方法, 并通过IoC方式,将值注入给Aciton。4、Action调用业务逻辑组件处理业务逻辑,这一步包含表单验证。5、Action执行完毕,根据 struts.xml中的配置找到对应的返回结果result

jstl,el,ognl的区别

jstl——JSP Standard Tag Library, el——Expressiong Language ognl——Object Graph Notation Language。 一种是标签,一种是表达式。 jstl能用于servlet和jsp中, struts标签针对于使用了struts的项目。 而el表达式是应用在JSP中,简化一些代码用的。 而struts2默认的是ognl表达式,

struts2 struts.xml常用常量配置

<constant name="struts.i18n.encoding" value="UTF-8" /> 指定Web应用的默认编码集,相当于调用HttpServletRequest的setCharacterEncoding方法 <constant name="struts.ui.theme" value="simple" /> 设置页面struts标签的样式     <consta

struts 页面取值问题

Struts2中的OGNL表达式语言是对Xwork的OGNL的封装。我们要理解一下几点:  1 . Struts2 中将 ActionContext 作为 OGNL 的上下文环境( ActionContext 内部含有一个 Map 对象)   2 . Struts2 中的 OGNL 表达式语言的根对象是一个 ValueStack , ValueStack 中的每一

struts和struts2的区别

2012-07-08 14:30 liujunzyf | 分类:JAVA相关 | 浏览8116次 分享到: 2012-07-08 14:41 提问者采纳 你问的应该是 struts1 和struts2 的区别:Struts2与Struts1的对比 1,在Action实现类方面: Struts1要求Action类继承一个抽象基类;Str

struts通配符配置

通配符配置 <!--method属性值为1表示匹配一个*。如用户的请求是book_add.action。则name的属性值是book_add,method的属性值是add  --><action name="book_*" class="action.AddBook" method="{1}"><result name="success">/success.jsp</result><

struts.xml与Web.xml的配置

web.xml的配置 <?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://jav