哥们们救我!!!javax.servlet.jsp.JspException: Cannot find bean xxx in any scope

lyhang801 2006-03-03 02:35:26
<%@ page contentType="text/html; charset=ISO8859_1" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.util.*"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html locale="true">
<head>
<title>单选框</title>
</head>
<body>
<html:form action="/login2.do" >
<html:radio property="radioval" value="xx"/>ff<br>
<html:radio property="radioval" value="yy"/>ee<br>
<input type="button" name="Button" value="提交" onClick="tijiao(this.form.color)">
</html:form>
<%
List list=(List)request.getAttribute("RadioForm");
out.print(request.getAttribute("ggg"));
%>
<logic:notEmpty name="RadioForm" property="radioval">
<bean:write name="RadioForm" property="radioval"/>
</logic:notEmpty>
</body>
</html:html>

actionform为:

package page1;
import org.apache.struts.action.ActionForm;
import org.apache.struts.upload.FormFile;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMessage;
public class RadioForm extends ActionForm{
private String radioval="xx";
public RadioForm(){
}
public void setRadioval(String radioval) {
this.radioval = radioval;
}
public String getRadioval() {
return this.radioval;
}
}

action为:
import java.util.*;
import javax.servlet.ServletContext;
import javax.sql.DataSource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.http.*;


public final class Login2 extends Action{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
RadioForm hff=(RadioForm) form;
request.setAttribute("RadioForm",hff.getRadioval());
return(mapping.findForward("success"));

}
}

将<logic:notEmpty name="RadioForm" property="radioval">
<bean:write name="RadioForm" property="radioval"/>
</logic:notEmpty>
就没错了,我要崩溃了.谢谢哥们们
...全文
487 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
interpb 2006-03-03
楼上都对了

Struts的标签不是很友好

最好仔细看看文档
回复
lyhang801 2006-03-03
我将jsp改为
<%

request.setAttribute("RadioForm",request.getAttribute("RadioForm"));

%>
<logic:notEmpty name="RadioForm" property="radioval">
<bean:write name="RadioForm" property="radioval"/>
</logic:notEmpty>

action改为
RadioForm hff=(RadioForm) form;

//hff.setRadioval("xx");
//HttpSession session=request.getSession();
request.setAttribute("RadioForm",hff);
request.setAttribute("ggg",hff.getRadioval());
return(mapping.findForward("success"));

还是报同样的错
回复
wmzsl 2006-03-03
没什么,你应该用JSTL!
你的错误就是在范围内找不到变量
回复
TrampEagle 2006-03-03
这个属于典型的标签误用。
是这样的,如果你用一个集合对象,然后你才可以用<logic:notEmpty name="RadioForm" property="radioval">,因为这时它的属性不为空,但是你的返回对象仅为一个String,所以是不能用这个标签的,你可以用<bean:write name="RadioForm"/>.
对于list或ArrayList等大的集合对象列表,或是Vector,map,set等的对象封装集合,你应该使用
<logic:present name="list">
<logic:notEmpty name="list">
<logic:iterate id="beanName" name="list">
<bean:write name="beanName" property="beanProperty"/>
</logic:iterate>
</logic:notEmpty>
</logic:present>
那么对于一个非String对象,如一个FormBean,你就应该用
<bean:write name="beanName" property="beanProperty"/>
来获取它的属性的值!
各种情况时有分别的,所以要搞清楚!
回复
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2006-03-03 02:35
社区公告
暂无公告