struts中的组合框

时间:2012-02-13 14:18:30

标签: java jsp combobox struts

嗨我想在struts 1.2中填充一个组合框,但我有一些例外 这是我的代码

DTO

public class GroupDTO {
    public GroupDTO() {
        // TODO Auto-generated constructor stub
    }

    private String value;
    private String lable;

    public GroupDTO(String value,String lable){
        this.value = value;
        this.lable = lable;
    }

    public String getLable() {
        return lable;
    }

    public void setLable(String lable) {
        this.lable = lable;
    }

    public String getValue() {
        return value;
    }

}

动作类

public class DualListBoxAction extends Action {

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    // TODO Auto-generated method stub

    List<GroupDTO> groupList = new ArrayList<GroupDTO>();
    GroupDTO groupDTO = null;
    groupDTO = new GroupDTO("1", "group1");
    groupList.add(groupDTO);
    groupDTO = new GroupDTO("2", "group2");
    groupList.add(groupDTO);
    groupDTO = new GroupDTO("3", "group3");
    groupList.add(groupDTO);
    groupDTO = new GroupDTO("4", "group4");
    groupList.add(groupDTO);

    HttpSession session = request.getSession();
    session.setAttribute("groupList", groupList);

      return mapping.findForward("success");
}

}

表单bean

public class DualListBoxForm extends ActionForm {

/**
 * 
 */
private static final long serialVersionUID = 1L;

private String groupName;

public String getGroupName() {
    return groupName;
}

public void setGroupName(String groupName) {
    this.groupName = groupName;
}

public static long getSerialversionuid() {
    return serialVersionUID;
}   
}

的struts-config.xml

<struts-config>

<form-beans>
    <form-bean name="dualListBoxForm" type="com.dss.form.DualListBoxForm"/>
</form-beans>   

<action-mappings>
    <action path="/dualListBox" scope="session" type="com.dss.action.DualListBoxAction" name="dualListBoxForm">
        <forward name="success" path="/dualListBox.jsp" />
    </action>
</action-mappings> 

的index.jsp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<jsp:forward page="dualListBox.do"></jsp:forward>
</body>
</html>

dualListBox.jsp

    <%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> 
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Dual List Box</title>
</head>
<body>
       <h1>Struts: Using HTML Options Tag Example</h1>

        Please select the menu.

        <h1>hello hello</h1>
        <html:form action=”dualListBox”>
            <html:select property=”menu” >

                <html:option value=”">–SELECT–</html:option>

                <html:options collection=”groupList” property=”value” labelProperty=”label” />

            </html:select> 

        </html:form>
</body>
</html>

错误

org.apache.jasper.JasperException: /dualListBox.jsp(17,27) quote symbol expected
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
    at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
    at org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:198)
    at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:148)
    at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1208)
    at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1422)
    at org.apache.jasper.compiler.Parser.parse(Parser.java:130)
    at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:255)
    at org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:185)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:347)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:326)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
    at org.apache.struts.chain.commands.servlet.PerformForward.handleAsForward(PerformForward.java:113)
    at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:96)
    at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)
Feb 13, 2012 7:26:03 PM org.apache.struts.chain.commands.AbstractExceptionHandler execute
WARNING: Unhandled exception

2 个答案:

答案 0 :(得分:1)

dualListBox.jsp中,您有“花哨的引号”或“智能引号”,例如,请将其替换为"

通常,当您复制&amp;粘贴来自博客的代码,该博客使用替换"以用于样式/印刷目的。

要解决注释中的错误,你需要在你的bean中使用getter和setter,如果你正在使用eclipse,你可以点击source > generate getters and setters

答案 1 :(得分:0)

html:options labelProperty存在问题。您将值设置为label,但GroupDTO bean只有一个名为lable的属性。将html:options更改为:

<html:options collection="groupList" property="value" labelProperty="lable" />