java.lang.ClassCastException
不是说得很清楚了吗?可能是数据类型转行的问题。
比较容易犯的一个错误。
不是说得很清楚了吗?可能是数据类型转行的问题。
比较容易犯的一个错误。
解决方案 »
- struts通过oracle数据库验证的登陆怎么写啊
- 如何把带有子查询的SQL转换成HQL
- 我想成为程序员,前辈们指点下我
- JSP 数据库输出
- Java开源项目管理工具
- 高分求助,JDOM build(InputStream)问题!
- 怎样把Document对象直接变成输出流,写入一个空文件变成XML文档?
- 如何在Struts下的Control模块下使用JspSmartUpload?
- 请教EJB总体结构是怎样的?
- org.hibernate.AnnotationException: No identifier specified for entity:
- ***100分难题:如何在不重启tomcat的情况下替换javabean?****
- weblogic8处理字符问题能用filter处理么?(散分处理)
那几个BEAN都编译通过了的啊!,怎么去找这个错误,谢谢!!!
请问你想要看哪个代码呢??是视图文件,还是各个BEAN文件!!!
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %><html:html locale="true">
<head>
<title><bean:message key="hello.jsp.title"/></title>
<html:base/>
</head>
<body bgcolor="white"><p> <h2><bean:message key="hello.jsp.page.heading"/></h2><p> <html:errors/><p> <logic:present name="personbean" scope="request">
<h2>
<bean:message key="hello.jsp.page.hello"/>
<bean:write name="personbean" property="userName" />!<p>
</h2>
</logic:present> <html:form action="/HelloWorld.do" focus="userName" > <bean:message key="hello.jsp.prompt.person"/>
<html:text property="userName" size="16" maxlength="16"/><br> <html:submit property="submit" value="Submit"/>
<html:reset/> </html:form><br> <html:img page="/struts-power.gif" alt="Powered by Struts"/> </body>
</html:html>
就这个简单的文件,输入名字,然后显示名字!!!
ACTIONSERVLET BEAN:
package hello;import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.util.MessageResources;public final class HelloAction extends Action
{
public ActionForward execute( ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response ) throws Exception
{
MessageResources messages = getResources( request );
ActionErrors errors = new ActionErrors( );
String userName = ( String ) ( ( HelloForm ) form ).getUserName( );
String badUserName = "xiaoqiang";
if( userName.equalsIgnoreCase( badUserName ) )
{
errors.add( "username", new ActionMessage( "hello.dont.talk.to.xiaoqiang", badUserName ) );
saveErrors( request, errors );
return ( new ActionForward( mapping.getInput( ) ) );
}
PersonBean pb = new PersonBean( );
pb.setUserName( userName );
pb.saveToPersistentStore( );
request.setAttribute( Constants.PERSON_KEY, pb );
request.removeAttribute( mapping.getAttribute( ) );
return ( mapping.findForward( "SayHello" ) );
}
}ACTIONFORM BEAN:
package hello;import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;public final class HelloForm extends ActionForm
{
private String userName = null;
public String getUserName( )
{
return this.userName;
}
public void setUserName( String userName )
{
this.userName = userName;
}
public void reset( ActionMapping mapping, HttpServletRequest request )
{
this.userName = null;
}
public ActionErrors validate( ActionMapping mapping, HttpServletRequest request )
{
ActionErrors errors = new ActionErrors( );
if( ( userName == null ) || ( userName.length( ) < 6 ) )
errors.add( "username", new ActionMessage( "hello.no.username.error" ) );
return errors;
}
}PERSONBEAN:
package hello;public class PersonBean
{
private String userName = null;
public String getUserName( )
{
return this.userName;
}
public void setUserName( String userName )
{
this.userName = userName;
}
public void saveToPersistentStore( )
{
}
}CONSTANTBEAN:
package hello;public final class Constants
{
public static final String PERSON_KEY = "personbean";
}
就是这些了,谢谢各位帮我看看!!!
ActionMessages errors = new ActionMessages( ); //结果编译就出错saveErrors( request, errors );!从错误看以后,我改成它的子类ActionErrors ...就编译通过了,我就怀疑书上的错误!!!
现在编译通过,运行出现另外错误,我就不知道怎么解决了,所以才求各位帮忙!!!我想大家明白我的意思了吧!!!
你应该把那
######################
<logic:present name="personbean" scope="request">
<h2>
hello.jsp.page.hello
<bean:write name="personbean" property="userName" />!<p>
</h2>
</logic:present>
######################
放到form里面
你试一下这个jsp
############################
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %><html:html locale="true">
<head>
<title><bean:message key="hello.jsp.title"/></title>
<html:base/>
</head>
<body bgcolor="white"><p> <h2><bean:message key="hello.jsp.page.heading"/></h2><p> <html:errors/><p> <html:form action="/HelloWorld.do" focus="userName" >
<logic:present name="personbean" scope="request">
<h2>
<bean:message key="hello.jsp.page.hello"/>
<bean:write name="personbean" property="userName" />!<p>
</h2>
</logic:present>
<bean:message key="hello.jsp.prompt.person"/>
<html:text property="userName" size="16" maxlength="16"/><br> <html:submit property="submit" value="Submit"/>
<html:reset/> </html:form><br> <html:img page="/struts-power.gif" alt="Powered by Struts"/> </body>
</html:html>############################
谢谢你,但是那没问题!!那只是输出结果!!!!因为视图文件,就一个!!!TO:spiritsl(梦雨心蓝) (
你的意思是什么?不太明白!!
H:\Tomcat\webapps\mystruts1\WEB-INF\classes\HelloAction.java:24: saveErrors(javax.servlet.http.HttpServletRequest,org.apache.struts.action.ActionErrors) in org.apache.struts.action.Action cannot be applied to (javax.servlet.http.HttpServletRequest,org.apache.struts.action.ActionMessages)
saveErrors( request, errors );
^
1 error请大家回答我想解决的问题吧,谢谢了!!!解决问题,分可以再给!!
该为
ActionErrors errors = new ActionErrors();
只是它的BEAN文件有问题,就如我说的那样!!再看看吧