p27 p27 - 6 months ago 19
Java Question

combo box in struts

hi i am trying to populate a combo box in struts 1.2 but i got some exception
here is my code

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;
}

}


action class

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");
}

}


form 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>


error

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

Answer

In dualListBox.jsp you have "fancy quotes" or "smart quotes" like replace them with ".

Usually this happens when you copy & paste code from a blog that uses to replace " for stylistic/typographic purposes.

To solve the error in the comment, you need getters and setters in your bean, if you're using eclipse you can just click source > generate getters and setters