Topic: WebWork在取得Parameters後,會出現ClassCastException??

  Print this page

1.WebWork在取得Parameters後,會出現ClassCastException?? Copy to clipboard
Posted by: arezus
Posted on: 2004-11-27 01:03

WebWork在取得Parameters後,從Map裡面把String取出時會出現ClassCastException
JDK:j2sdk1.4.2_05
Tomcat: 4.1.27
以下是 一個 Action程式碼 execute()部分

public String execute()
{
ActionContext ctx = ActionContext.getContext();
Map session = ctx.getSession();
String id = (String)session.get("user_id");
OvrTimeModel ovrt = new OvrTimeModel();
years = ovrt.getYear();
months = ovrt.getMonthList();
Map params = ctx.getParameters();
if(params.get("year")==null)
{
thisYear = ovrt.getYYY();
thisMonth = ovrt.getMM();
}
else
{
thisYear = (String)params.get("year");//<---會丟出ClassCastException
thisMonth = (String)params.get("month");
}
return SUCCESS;
}

執行到 thisYear = (String)params.get("year"); 就會發生 CastException

exception

java.lang.ClassCastException
at com.webwork.apps.fees.OverTimeFees58.execute(OverTimeFees58.java:38)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:168)
at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:115)
at com.opensymphony.webwork.dispatcher.ServletDispatcher.serviceAction(ServletDispatcher.java:229)
at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:199)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

xwork.xml

<xwork>

<include file="webwork-default.xml"/>
  
  <package name="feesWork" extends="webwork-default" namespace="/fees" >
    <action name="initOvrTimeFees58" class="com.webwork.apps.fees.OverTimeFees58" >
      <interceptor-ref name="defaultStack" />
      <result name="success" type="dispatcher">
        <param name="location">/xwork/fees/OverTimeFees58.jsp</param>
      </result>
    </action>>
  </package>

</xwork>


/xwork/fees/OverTimeFees58.jsp
部分網頁

<form name="form1" method="post" action="initOvrTimeFees58.action">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="250" bgcolor="#FFFFFF">
   <ww:select label="'年'" name="'year'" list="years" value="thisYear" />
   <ww:select label="'月份'" name="'month'" list="months" value="thisMonth" />
   <ww:submit value="'送出'"/>
</table>  
</div>
<br>
</form>

2.Re:WebWork在取得Parameters後,會出現ClassCastException?? [Re: arezus] Copy to clipboard
Posted by: daviszw
Posted on: 2004-12-06 13:07

是不是没用ParametersInterceptor呀

3.Re:WebWork在取得Parameters後,會出現ClassCastException?? [Re: arezus] Copy to clipboard
Posted by: daviszw
Posted on: 2004-12-06 13:09

噢,不好意思,刚看到你的jsp代码,原来上因为select标签在action里得到的是String数组


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923