标签里如何使用javabean,如

wzx7934003 2005-05-12 01:20:55
请问各位
我第一次使用标签,想用到他的if功能,我写了如下代码
<c:if test="${<%view.getStatus()==1%>}">
可是好象通不过,不知道是为什么,难道不能使用javabean里的方法进行判断吗?还请指教,谢谢
...全文
1302 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
bp69 2005-05-13
  • 打赏
  • 举报
回复
标签不能直接放在<%%>内
fashchina 2005-05-13
  • 打赏
  • 举报
回复
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="com.pos.model.InfoGether,com.pos.view.SoView" %>
<%@ page import="com.pos.model.InfoGether,com.pos.view.UserView" %><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
SoView view=(SoView)(result.get(5));
<c:if test="${view.getStatus()==1}">
....
</c:if>

%>


--->

<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="com.pos.model.InfoGether,com.pos.view.SoView" %>
<%@ page import="com.pos.model.InfoGether,com.pos.view.UserView" %><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
SoView view=(SoView)(result.get(5));
%>
<c:if test="${view.status==1}">
....
</c:if>





给个简单的例子:
index.jsp

<%@ page import="com.business.ComJstl" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
ComJstl com=new ComJstl();
com.setUsername("yuhua");
request.setAttribute("com",com);
%>
<c:if test="${not empty com.username}">
<c:out value="${com.username}" />
</c:if>


com.business.ComJstl

package com.business;

/**
* @author Bluewater
*
*/
public class ComJstl {

public ComJstl(){

}

private String username="";
private String password="";

/**
* @return 返回 password。
*/
public String getPassword() {
return password;
}
/**
* @param password 要设置的 password。
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @return 返回 username。
*/
public String getUsername() {
return username;
}
/**
* @param username 要设置的 username。
*/
public void setUsername(String username) {
this.username = username;
}
}


如果上面的代码还不能运行,那我真的没话说了
gyljfang 2005-05-13
  • 打赏
  • 举报
回复

<%
SoView view=(SoView)(result.get(5));
%>
<c:if test="<%=view.getStatus()==1%>">
....
</c:if>


错误有两个 一:<c:if >....</c:if>不能放在<%%>中
二:${...}中间变量值只能是通过page,Request、Session、Application得到
青盟日志 2005-05-13
  • 打赏
  • 举报
回复
<c:if test="<%=view.getStatus()==1%>">
不能在<%%>前后加${}!
wzx7934003 2005-05-13
  • 打赏
  • 举报
回复
以下是我的代码
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="com.pos.model.InfoGether,com.pos.view.SoView" %>
<%@ page import="com.pos.model.InfoGether,com.pos.view.UserView" %><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
SoView view=(SoView)(result.get(5));
<c:if test="${view.getStatus()==1}">
....
</c:if>

%>
fashchina 2005-05-12
  • 打赏
  • 举报
回复
你的代码
wzx7934003 2005-05-12
  • 打赏
  • 举报
回复
楼上的兄弟,照你们说的做了,可会出现如下错误
The function getStatus must be used with a prefix when a default namespace is not specified
请问是怎么回事
fashchina 2005-05-12
  • 打赏
  • 举报
回复
先确保在session/paeg/request/app..范围内,有这个bean变量
然后这么写
<c:if test="${view.status==1}">
....
..

</c:if>
青盟日志 2005-05-12
  • 打赏
  • 举报
回复
不好意思,我说错了,更正一下你的
<c:if test="${<%view.getStatus()==1%>}">
是正确的,但应该在view前面加=
这样<c:if test="${<%=view.getStatus()==1%>}">
青盟日志 2005-05-12
  • 打赏
  • 举报
回复
不可以这样写
因为${...}这样的语法是EL表达式,与
<%...%>这样的scriptlet表达式是不同的,所以不能通用
如果你的view.getStatus()中的view是<c:forEach 中的varStatus属性的值,那么,你可以用这这样的写法表示<c:if test="${view.index==1}">或是<c:if test="${view.count==1}">.
飞行的兔子 2005-05-12
  • 打赏
  • 举报
回复
{<%=view.getStatus()==1%>

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧