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 ...
随机推荐
- win-zabbix_agent端配置解析
Zabbix agent 在windows上安装部署 部署windows服务器需要在agent服务器上添加到10.4.200.2的路由 蓝泰服务器需要添加10.0.90.5的网关,联通的机器需要添加到 ...
- Docker学习笔记 - Docker容器的网络基础
一.虚拟网桥 docker0 docker0 是 linux的虚拟网桥,守护进程通过docker0给容器提供网络连接的各种服务. 网桥是数据链路层设备,通常ip地址是网络层的设置.linux的虚拟网桥 ...
- python 模拟浏览器登陆coursera
import requests import random import string def randomString(length): return ''.join(random.choice(s ...
- SQL查询语句练习
最近在学习SQL嘛,所以各个地方找题目来练手,毕竟现在能离得开数据库么? Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C ...
- cache和buffer
一.free命令是Linux查看内存使用情况的命令 1. centos 7风格 [root@bogon init.d]# free -m total used free shared buff/cac ...
- POJ-2586 Y2K Accounting Bug贪心,区间盈利
题目链接: https://vjudge.net/problem/POJ-2586 题目大意: MS公司(我猜是微软)遇到了千年虫的问题,导致数据大量数据丢失.比如财务报表.现在知道这个奇特的公司每个 ...
- hdu1443 Joseph---约瑟夫环
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1443 题目大意: 一共有2k个人,分别为k个好人和k个坏人,现在我们需要每隔m个人把坏人挑出来,但是 ...
- 用PHP如何实现这种乘法口诀表?
用PHP如何实现这种乘法口诀表? 1x1=1 ,1x2=2 ,1x3=3 ,.....,1x9=9 2x2=4 ,2x3=6 ,......,2x9=18 ........ ...... 8x8=64 ...
- Hive DQL详解
1.select语法 SELECT [ALL | DISTINCT] select_expr, select_expr, ... FROM table_reference [WHERE where_c ...
- [NOI 2011]道路修建
Description 在 W 星球上有 n 个国家.为了各自国家的经济发展,他们决定在各个国家 之间建设双向道路使得国家之间连通.但是每个国家的国王都很吝啬,他们只愿 意修建恰好 n – 1条双向道 ...