struts2 可以用ognl拿到值而不可以用el拿到值的解决方法
错误debug后
得到了There is no read method for container的错误
于是我new了一个实体类
package com.unity;
public class Student {
private String studentName;
public Student(String studentName) {
this.studentName = studentName;
}
public String getStudentName() {
return studentName;
}
//
public void setStudentName(String studentName) {
this.studentName = studentName;
}
}
并在action导入
package com.action; import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.util.ValueStack;
import com.unity.Student; public class HelloWorldAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = -7840227232203094654L;
private String studentName; public String getStudentName() {
return studentName;
} public void setStudentName(String studentName) {
this.studentName = studentName;
} private String password; public String execute() {
System.out.println("execute.....");
System.out.println("studentName:" + studentName);
System.out.println("password:" + password);
// ValueStack vs=ActionContext.getContext().getValueStack();
ActionContext context = ActionContext.getContext();
ValueStack vs = context.getValueStack();
// 值栈的栈顶 Student student = new Student("111111"); vs.push(student);
return "info";
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
}
}
虽然没有了There is no read method for container的错误
但是依然无法用el得到值
所以debug可以去死了
后来直接翻墙啃英文的狗屎
发现有一个版本的structs2
默认关了页面的el表达式
强制你使用ognl.........
最终解决方法
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%> //isELIgnored 是否无视el表达式 重新设置为false
但是我后来发现第二个解决方法
同一版本的structs2在不使用maven的情况下
倒没有出现这样的问题
最后总结
为了规范,哥们在maven的情况下,用struts2就用ogln吧,硬是用el加上那句isELIgnored="false"就行了 ,
最后放点取值的方法
<br> 密码:${password }
<br> 姓名1:<%=request.getParameter("studentName")%>
<br> 姓名2:${studentName}
<br> 姓名3:
<s:property value="[0].studentName" />
<br> 姓名4:
<s:property value="[1].studentName" />
<br> 姓名5:${requestScope.studentName}
public class HelloWorldAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = -7840227232203094654L;
private String studentName;
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
private String password;
public String execute() {
System.out.println("execute.....");
System.out.println("studentName:" + studentName);
System.out.println("password:" + password);
// ValueStack vs=ActionContext.getContext().getValueStack();
ActionContext context = ActionContext.getContext();
ValueStack vs = context.getValueStack();
// 值栈的栈顶
Student student = new Student("111111");
vs.push(student);
return "info";
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
public class Student {
private String studentName;
public Student(String studentName) {
this.studentName = studentName;
}
public String getStudentName() {
return studentName;
}
//
public void setStudentName(String studentName) {
this.studentName = studentName;
}
}
图片

struts2 可以用ognl拿到值而不可以用el拿到值的解决方法的更多相关文章
- 不能将X*类型的值分配到X*类型的实体问题的解决方法
今天在学习链表的过程中遇到了这个问题,我用如下方法定义了一个结构体,然后这个函数想要在链表头插入一个节点.但是在函数的最后一行却出现了报错:不能将MyLinkedList * 类型的值分配到MyLin ...
- Win10 “此环境变量太大。此对话框允许将值设置为最长2047个字符。" 解决方法。
打开注册表 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment 双击右边的 Path (RE ...
- [转]STRUTS2中的OGNL
OGNL表达式是(Object-Graph Navigation Language)是对象图形化导航语言.OGNL是一个开源的项目,struts2中默认使用OGNL表达式语言来显示数据.与serlve ...
- (补充)9.Struts2中的OGNL表达式
OGNL表达式概述 1. OGNL是Object Graphic Navigation Language(对象图导航语言)的缩写 * 所谓对象图,即以任意一个对象为根,通过OGNL可以访问与这个对象关 ...
- .Net调用Java编写的WebServices返回值为Null的解决方法(SoapUI工具测试有返回值)
最近在项目中与别的公司对接业务,对方是Java语言,需要调用对方的WebServices,结果常规的添加web引用的方法可以传过去值,但是返回值为null 查了很多资料,没有解决方法 思考应该是.Ne ...
- 【基于初学者的SSH】struts2 值栈的详解与struts2标签库+ognl表达式
一:什么是值栈:struts2里面本身提供的一种存储机制,类似于域对象,值栈,可以存值和取值 特点:先进后出,最上面的元素叫做栈顶,也叫压栈. <s:debug></s:debug& ...
- struts2中,OGNL访问值栈的时候查找的顺序是什么?请排序:模型对象、临时对象、固定名称的对象、Action对象
struts2中,OGNL访问值栈的时候查找的顺序是什么?请排序:模型对象.临时对象.固定名称的对象.Action对象 解答:struts2的值栈排列顺序为:1).临时对象:2).模型对象:3).Ac ...
- Struts2中的OGNL表达式
一.OGNL表达式简介 OGNL是Object Graphic Navigation Language(对象图导航语言)的缩写,它是一个开源项目.所谓对象图,即以任意一个对象为根,通过OGNL可以访问 ...
- Struts2入门(五)——OGNL和标签库
一.前言 OGNL和标签库的作用,粗暴一点说,就是减少在JSP页面中出现java代码,利于维护. 1.1.OGNL 1.1.1.什么是OGNL? OGNL(Object-Graph Navigatio ...
随机推荐
- 如何排查CPU飙升的Java问题
1. JPS 查看jvm进程 2. 显示线程列表 ps -mp pid -o THREAD,tid,time 找到了耗时最高的线程tid 3. tid转换成16进制 printf "%x\n ...
- sts 和 lombok
1.安装lombok.jar到sts.exe所在目录 如果是eclipse,需要放到eclipse.exe所在目录,同理myeclipse. 2.修改sts.ini配置使用lombok 如果是ecli ...
- hadoop2.7.3+spark2.1.0+scala2.12.1环境搭建(3)http://www.cnblogs.com/liugh/p/6624491.html
一.文件准备 scala-2.12.1.tgz 下载地址: http://www.scala-lang.org/download/2.12.1.html 二.工具准备 2.1 Xshell 2.2 X ...
- python入门(3)python的解释器
python入门(3)python的解释器 Python写的程序是以.py为扩展名的文本文件.要运行代码,就需要Python解释器去执行.py文件. 由于整个Python语言从规范到解释器都是开源的, ...
- ssh整合之二hibernate单独搭建
1.首先我们需要去拷贝我们的hibernate所需的jar包 这里还需要加入我们C3P0的jar包,因为我们hibernate中使用的C3P0连接池 2. 编写我们的关系映射文件Customer.c ...
- spring9——AOP之AspectJ对AOP的实现
从上述的实验中可以看出BeanNameAutoProxyCreator对于AOP的实现已经和完美了,但是还有两点不足之处: 1,对于切面的实现比较麻烦,既不同类型的通知切面要实现不同的接口,而且一个切 ...
- 判断一个字符串是不是一个合法的IP地址
最近在笔试的时候遇到碰一道算法题, 要求判断一个字符串是不是合法的ip地址. 将我的思路发出来分享一下,不一定正确,也不一定是最优的方法.希望能分享一些交流 要求用java或者c来实现,我的java代 ...
- python 类和对象
类和对象 类 1.类的组成 数据和函数,二者是类的属性 2.两个作用: 实例化 属性引用 属性引用:类名.属性(增删改查) 实例化: 类名加括号就是实例化,会自动出发__init__的运行 ...
- zipline-benchmarks.py文件改写
改写原因:在这个模块中的 get_benchmark_returns() 方法回去谷歌财经下载对应SPY(类似于上证指数)的数据,但是Google上下载的数据在最后写入Io操作的时候会报一个恶心的编码 ...
- mysql中出现Unknown column 'qwe' in 'field list'的错误
下面是我建表的代码 输入数据的代码 可以看到出现了类似Unknown column 'qwe' in 'field list'的错误 当时看了好久改了又改都没有找到错误,直道我在一次打C语言代码的过程 ...