找不到豆子:" wlist"在任何范围内

时间:2016-05-12 02:15:19

标签: jsp struts-1

我是java web项目的初学者,试图找出导致异常javax.servlet.jsp.JspException: Cannot find bean: "wlist" in any scope的原因。任何帮助将不胜感激。

异常发生在:

</ul>

<div class="index_news clearfix">
<logic:iterate id="w" type="com.wxkm.data.model.Tsubj" name="wlist">
    <dl class="news_dl clearfix">
        <dt>
            <logic:notEmpty name="w" property="npic">
            <a href="../../p/showsub/${w.id }.html" ><img src="../../resources/report/${w.npic }" width="150" height="110"></a>
            </logic:notEmpty>
            <logic:empty name="w" property="npic">
            <a href="../../p/showsub/${w.id }.html" ><img src="../../resources/img/default.jpg" width="150" height="110"></a>
            </logic:empty>
        </dt>
        <dd>
            <h2><a href="../../p/showsub/${w.id }.html" ><%String ntitle=w.getNtitle();ntitle=ntitle==null?"":ntitle;if(ntitle.length()>23){out.print(ntitle.substring(0,23)+"...");}else{out.print(ntitle);} %></a></h2>
            <p><a href="../../p/showsub/${w.id }.html">${w.ndigest }...</a></p>
        </dd>
     </dl>
</logic:iterate>     

  </div>

Tsubj课程:

package com.wxkm.data.model;

public class Tsubj {
    private int id;
    private String ntitle;
    private String npic;
    private String ndigest;
    private int ntype;
    private String ndate;
    private String sflag;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getNdate() {
        return ndate;
    }
    public void setNdate(String ndate) {
        this.ndate = ndate;
    }
    public String getNdigest() {
        return ndigest;
    }
    public void setNdigest(String ndigest) {
        this.ndigest = ndigest;
    }
    public String getNpic() {
        return npic;
    }
    public void setNpic(String npic) {
        this.npic = npic;
    }
    public String getNtitle() {
        return ntitle;
    }
    public void setNtitle(String ntitle) {
        this.ntitle = ntitle;
    }
    public int getNtype() {
        return ntype;
    }
    public void setNtype(int ntype) {
        this.ntype = ntype;
    }
    public String getSflag() {
        return sflag;
    }
    public void setSflag(String sflag) {
        this.sflag = sflag;
    }
}

struts-config中的操作行:

<action path="/p/show/showm" type="com.wxkm.struts.action.showm" scope="request">
    <forward name="suc" path="/pages/hpage/showm.jsp"/>
    <forward name="failed" path="/p/hpage/toLogOut.do" redirect="true"/>
</action>

获取wlist(showm.java)的动作类:

package com.wxkm.struts.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.wxkm.data.impl.TlogImpl;
import com.wxkm.data.impl.TsubjImpl;
import com.wxkm.data.impl.WcontImpl;
import com.wxkm.data.model.Tsubj;
import com.wxkm.data.model.Wcont;
import com.wxkm.res.GlobalProperty;

public class showm extends Action {

    /* forward name="suc" path="/pages/hpage/showm.jsp" */
    private final static String SUC = "suc";

    /* forward name="failed" path="/p/hpage/toLogOut.do" */
    private final static String FAILED = "failed";

    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        // TODO process request and return an ActionForward instance, for example:
        // return mapping.findForward(SUC);

        //List<Wcont> wlist=WcontImpl.getInstance().getWcontListByMid(0, "0",0);
        List<Tsubj> wlist=TsubjImpl.getInstance().getTsubjList("0",1,4);
        request.setAttribute("wlist", wlist);

        //金融
        List<Wcont> wlist1=WcontImpl.getInstance().getWcontListByMid(27,"0",1,GlobalProperty.RowNum8);
        request.setAttribute("wlist1", wlist1);

//      房地产
        List<Wcont> wlist2=WcontImpl.getInstance().getWcontListByMid(28,"0",1,GlobalProperty.RowNum8);
        request.setAttribute("wlist2", wlist2);

//      房产基金
        List<Wcont> wlist3=WcontImpl.getInstance().getWcontListByMid(29,"0",1,GlobalProperty.RowNum8);
        request.setAttribute("wlist3", wlist3);

//      交通基建
        List<Wcont> wlist4=WcontImpl.getInstance().getWcontListByMid(30,"0",1,GlobalProperty.RowNum8);
        request.setAttribute("wlist4", wlist4);

//      X产业
        List<Wcont> wlist5=WcontImpl.getInstance().getWcontListByMid(31,"0",1,GlobalProperty.RowNum8);
        request.setAttribute("wlist5", wlist5);

//      添加浏览记录
        TlogImpl.getInstance().settLog(request, "浏览了首页","");

        return mapping.findForward(SUC);
    }

}

showm.jsp

<%@ page language="java" contentType="text/html; charset=gb2312"    pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<%@ taglib uri="/tags/struts-tiles" prefix="tiles"%>
<tiles:insert definition="showm"/> 

1 个答案:

答案 0 :(得分:0)

<logic:iterate>添加范围可能有所帮助。 它应该看起来像

<logic:iterate id="w" type="com.wxkm.data.model.Tsubj" name="wlist" scope="request">