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 ...
随机推荐
- DSkin 的WebUI开发模式介绍,Html快速开发Winform的UI
新版WebUI开发模式采用MiniBlink内核,这个内核功能更完善,dll压缩之后才5M,而且提供开发者功能,内核还在更新中,而且是开源项目:https://github.com/weolar/mi ...
- Oracle10g物理DG详细配置方法及步骤
--测试环境: OS:Redhat linux(64) Primary: IP:192.168.94.198 SID:dgdb1 Hostname:dg1 DB_U ...
- SpringCloud的应用发布(三)vmvare+linux,xftp,xshell连接linux失败
Vmvare内的linux虚拟机已经启动,但是 xftp和xshell连接不上? 环境信息:子网 192.168.136.* linux ip:192.168.136.100 一.核对linux的ip ...
- maven编译时出现读取XXX时出错invalid LOC header (bad signature)
问题原因 该包没有下载正确. 解决办法 找到该包的目录,删除该包重新下载即可. 重新下载后用maven test一下,红叉消失.
- OAuth2.0学习(1-7)授权方式4-客户端模式(Client Credentials Grant)
授权方式4-客户端模式(Client Credentials Grant) 客户端模式(Client Credentials Grant)指客户端以自己的名义,而不是以用户的名义,向"服务提 ...
- 使用Java High Level REST Client操作elasticsearch
Java高级别REST客户端(The Java High Level REST Client)以后简称高级客户端,内部仍然是基于低级客户端.它提供了更多的API,接受请求对象作为参数并返回响应对象,由 ...
- 小技巧-C#文本快速删除空行
查找:^\s*\n 替换空格 选择正则表达式
- CSS 选择器简介
前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! 选择器权重 如果以4位数表示选择符权重,那么: 元素选择器的权重是1: id 选择器的权重为100: cl ...
- linux(centos)常用命令
原文:https://blog.csdn.net/zhangzhikaixinya/article/details/44538571 1.查看当前所在路径:pwd 2.新建文件夹www:mkdir w ...
- nodejs+express+mysql 增删改查(二)
1.最早一篇关于express框架简单的增删改查文章,http://www.cnblogs.com/zhengyeye/p/nodejs.html#3947308:意外走红博客园,无奈自己之前一直没有 ...