EL表达式取不到值,高手帮忙看看 ${product.name }取不到值,从数据库里确实拿到了数据,并且放在了request范围内,为什么在页面上取不到值 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 request是每个请求都新建一个的,数据放在request里以后如果用forward转到显示页然后用el表达式还是能取到request的值的,如果是redirect就取不到了。你先试试放在session里能不能拿到。如果能拿到,那就是request生命周期的问题了。 表现层我用的是struts控制转发,放在request里面不行吗? 你试试用{requestScope.product.name} 你的数据是放到request里面名为product的Attribute里面么?并且名为product的Attribute里面有getName()这个方法? 有啊product类里又getName()方法啊 你是如何放到request里面的,你贴些代码看看。另外你看一下页面上的位置里显示什么内容,是空的还是其他的。 ${product.name }你的product是怎么定义的发出来看看~ <% String name = ((Product)request.getAttribute("product")).getName(); System.out.println(name);%>试试这样能不能打印出来。 {requestScope.product.name},用这个 在程序里request.setAttribute("product",product);并且在bean里有getName()方法;另问下是struts1还是22的话直接set,get就行 你把对象方进request里面哪你有没有对request进行转发啊 用struts转发的时候也分redirect和forward呀。后者能给你保留request的。你看你转发的时候浏览器里地址栏的路径会不会变 我是这样写的://struts1.x,ProductAction中:List<product> produtListrequest.setAttribute("produtList", produtList);页面中:<c:forEach items="${produtList}" var="product">${product.name}</c:forEach>Product类中也有getName()和setName()方法 product是你存放信息的, 是你实体累name的私有字段, product有值一定能取到值 这种写法应该没问题是不是你的list中product就没有取到值啊?调试下程序,看看request.setAttribute("produtList", produtList);之前能不能取到值 我真的没法了,list中我打印了,确实取到了值。郁闷了一天了 用structs的标签库去取值 Java code//struts1.x,ProductAction中:List <product> produtListrequest.setAttribute("produtList", produtList); 页面中: Java code <logic:iterater id="${produtList}" var="product"> ${product.name} </logic:iterator> 肯能代码有点错,自己去看一下语法怎么样的?我以前也碰到这样的问题。 你放在作用域是不是这样的啊request.setAttribute("products",products);你的products是一个对象吧它里面肯定得有一个name属性吧,你确定一那一定有 是用的forward转发的么?还有,引用了jstl吗? 17书籍16书籍15书籍14书籍13书籍12书籍11书籍10书籍9书籍8书籍上面是从数据库取到的数据下面是tomcat的日志09-10-18 08:48:51 DEBUG [/]:185 - servletPath=/WEB-INF/page/product/productlist.jsp, pathInfo=null, queryString=null, name=null这哪错了 09-10-18 08:48:51 DEBUG [/]:371 - Path Based Forward 09-10-18 08:48:51 DEBUG [/]:404 - Disabling the response for futher output 17书籍16书籍15书籍14书籍13书籍12书籍11书籍10书籍9书籍8书籍09-10-18 08:48:51 DEBUG [/]:185 - servletPath=/WEB-INF/page/product/productlist.jsp, pathInfo=null, queryString=null, name=null 09-10-18 08:48:51 DEBUG [/]:371 - Path Based Forward 09-10-18 08:48:51 DEBUG [/]:404 - Disabling the response for futher output 在jsp上做一个测试,看一下这样能打出来吗?<% Product p1 = new Product (); p1.setName("测试"); p1.setAttribute("p1",p1)${p1.name} 从这里看是你的el表达式并没有被解析出来,你使用的tomcat版本是多少?你尝试使用6.0版本的试试。 正解,我也出现这个问题,发现语法先错了,老是把requestScope直接用request代替了,出了错还真找不出来, 关于jdbc 关于Action跳转的问题 FTP问题 如何在jsp中使用javascript,struts标签和jsp页面变量之间互相传值 jsp 日志列表 如何做才能让它显示部分内容 一个验证用户登录的javabean代码的问题????? servlet 急!!! 导入JSP系统后出现的问题 新闻发布如何实现 SQLException: Invalid authorization specification: Access denied for user: 'root@localhost' (Using password: YES)是什么错误! jsp如何生成qr二维码 jsp疑问
并且名为product的Attribute里面有getName()这个方法?
product类里又getName()方法啊
另外你看一下页面上的位置里显示什么内容,是空的还是其他的。
你的product是怎么定义的
发出来看看~
<%
String name = ((Product)request.getAttribute("product")).getName();
System.out.println(name);
%>
试试这样能不能打印出来。
并且在bean里有getName()方法;
另问下是struts1还是2
2的话直接set,get就行
哪你有没有对request进行转发啊
用struts转发的时候也分redirect和forward呀。后者能给你保留request的。你看你转发的时候浏览器里地址栏的路径会不会变
request.setAttribute("produtList", produtList);页面中:<c:forEach items="${produtList}" var="product">
${product.name}
</c:forEach>Product类中也有getName()和setName()方法
这种写法应该没问题
是不是你的list中product就没有取到值啊?
调试下程序,看看request.setAttribute("produtList", produtList);
之前能不能取到值
Java code//struts1.x,ProductAction中:List <product> produtListrequest.setAttribute("produtList", produtList);
页面中:
Java code <logic:iterater id="${produtList}" var="product">
${product.name} </logic:iterator>
肯能代码有点错,自己去看一下语法怎么样的?我以前也碰到这样的问题。
request.setAttribute("products",products);
你的products是一个对象吧
它里面肯定得有一个name属性吧,
你确定一那一定有
17书籍
16书籍
15书籍
14书籍
13书籍
12书籍
11书籍
10书籍
9书籍
8书籍
上面是从数据库取到的数据
下面是tomcat的日志09-10-18 08:48:51 DEBUG [/]:185 - servletPath=/WEB-INF/page/product/productlist.jsp, pathInfo=null, queryString=null, name=null这哪错了
09-10-18 08:48:51 DEBUG [/]:371 - Path Based Forward
09-10-18 08:48:51 DEBUG [/]:404 - Disabling the response for futher output
16书籍
15书籍
14书籍
13书籍
12书籍
11书籍
10书籍
9书籍
8书籍
09-10-18 08:48:51 DEBUG [/]:185 - servletPath=/WEB-INF/page/product/productlist.jsp, pathInfo=null, queryString=null, name=null
09-10-18 08:48:51 DEBUG [/]:371 - Path Based Forward
09-10-18 08:48:51 DEBUG [/]:404 - Disabling the response for futher output
Product p1 = new Product ();
p1.setName("测试");
p1.setAttribute("p1",p1)${p1.name}