跟着老师写的一模一样怎么我的一运行就500错误???下载的代码和老师课堂上讲的不一样?

jike_6754102 Struts2 标签 最后由 qq_5verd2nm 于2017年05月05日回复

  • 3 回答
  • 1.8k 浏览

jsp:

<%@ page language="java" import="java.util.*,java.lang.*,com.czq.struts.bean.*" pageEncoding="utf-8"%>

<%@ taglib prefix="s"  uri="/struts-tags"%>

<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <title>My JSP 'biaodan.jsp' starting page</title>

  </head>

  

  <body>

  

  <%

  Map<Dept,List<Emp>> map=new HashMap<Dept,List<Emp>>();

 

  Dept de1=new Dept(1,"开发部");

  Dept de2=new Dept(2,"产品部");

  Dept de3=new Dept(3,"市场部");

 

  Emp e1=new Emp(1,"李彦宏");

  Emp e2=new Emp(2,"马化腾");

  Emp e3=new Emp(3,"雷军");

  Emp e4=new Emp(4,"张小龙");

  Emp e5=new Emp(5,"陈志强");

  Emp e6=new Emp(6,"李小龙");

  Emp e7=new Emp(7,"马云");

  Emp e8=new Emp(8,"程维");

  Emp e9=new Emp(9,"余承东");

 

  List<Emp> list1=new ArrayList<Emp>();

  List<Emp> list2=new ArrayList<Emp>();

  List<Emp> list3=new ArrayList<Emp>();

 

  list1.add(e1);

  list1.add(e2);

  list1.add(e3);

 

  list2.add(e4);

  list2.add(e5);

  list2.add(e6);

 

  list3.add(e7);

  list3.add(e8);

  list3.add(e9);

 

  map.put(de1, list1);

  map.put(de2, list2);

  map.put(de3, list3);

 

  request.setAttribute("map", map);

  %>

 

  <s:doubleselect 

  formName="form1" 

  label="员工" 

 

  list="#request.map.KeySet()" 

  name="depId"

  id="comboId"

  listKey="dptId"

  listValue="dptName"

 

  doubleList="#request.map[top]" 

  doubleName="elId"

  doubleId="comboDoubleId"

  doubleListKey="elId"

  doubleListValue="userName"

  />

 

 

 

  </body>

</html>


实体类:

package com.czq.struts.bean;

public class Dept {

private int dptId;

private String dptName;

public int getDptId() {

return dptId;

}

public void setDptId(int dptId) {

this.dptId = dptId;

}

public String getDptName() {

return dptName;

}

public void setDptName(String dptName) {

this.dptName = dptName;

}

public Dept(int dptId, String dptName) {

this.dptId = dptId;

this.dptName = dptName;

}

}


package com.czq.struts.bean;

public class Emp {

private int elId;

private String username;

public Emp(int elId, String username) {

this.elId = elId;

this.username = username;

}

public int getElId() {

return elId;

}

public void setElId(int elId) {

this.elId = elId;

}

public String getUsername() {

return username;

}

public void setUsername(String username) {

this.username = username;

}

}


希望老师或同学看到帮忙解答一下,看了半天都不知道哪里错了

  • jike_6754102 2016年09月03日 回答 #1楼
  • 错误是:

    严重: Servlet.service() for servlet jsp threw exception

    tag 'doubleselect', field 'list', name 'depId': The requested list key '#request.map.KeySet()' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]

    at org.apache.struts2.components.Component.fieldError(Component.java:237)

    at org.apache.struts2.components.Component.findValue(Component.java:358)

    at org.apache.struts2.components.ListUIBean.evaluateExtraParams(ListUIBean.java:80)

    at org.apache.struts2.components.DoubleListUIBean.evaluateExtraParams(DoubleListUIBean.java:96)

    at org.apache.struts2.components.DoubleSelect.evaluateExtraParams(DoubleSelect.java:62)

    at org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:856)

    at org.apache.struts2.components.UIBean.end(UIBean.java:510)

    at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)

    at org.apache.jsp.WEB_002dINF.biaodan2_jsp._jspx_meth_s_005fdoubleselect_005f0(biaodan2_jsp.java:177)

    at org.apache.jsp.WEB_002dINF.biaodan2_jsp._jspService(biaodan2_jsp.java:123)

    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)

    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)

    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)

    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)

    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)

    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)

    at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:750)

    at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:720)

    at org.apache.jsp.index_jsp._jspService(index_jsp.java:92)

    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)

    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)

    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

  • 1 评论
  • qq_5verd2nm 2017年05月05日 回答 #3楼
  • 我发现我将#request.map.KeySet()改为#request.map.keySet()就好了,同时我加上<s:form></s:form>之后才正常显示

  • 0 评论