一个很简单关于Struts的问题

weizhihui1213 2006-02-22 03:01:49
我初接触Struts,根据资料写了一个简单的东东来测试下,除了action(myAction)中添加了一些语句外,其他均为自动产生,环境win2k+tomcat4.1+jBuilderx+struts1.0+JDK1.4.2,请各位指教,多谢。
如下:
-----myAction.java-------
package test;
import org.apache.struts.action.*;
import javax.servlet.http.*;

public class myAction extends Action {
public ActionForward perform(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
/**@todo: complete the business logic here, this is just a skeleton.*/
myActionForm myActionForm = (myActionForm) actionForm;
// throw new java.lang.UnsupportedOperationException("Method perform() not yet implemented.");
//---------------本人填写-------------------
String fieldA=myActionForm.getFieldA();
String fieldB=myActionForm.getFieldB();
myActionForm.setVResult(fieldA + fieldB);
return(actionMapping.findForward("input"));
//-------------------------------------------
}
}

------------input.jsp--------------
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ page contentType="text/html; charset=GBK" %>
<html:html>
<head>
<title>
input
</title>
</head>
<body>
<h1>JBuilder Generated Struts JSP for ActionForm test.myActionForm</h1>
<p>
<html:form action="/myAction.do" method="POST">
<html:text property="fieldA"/>
<br>
<html:text property="fieldB"/>
<br>
<html:text property="vResult"/>
<br>
<html:submit property="submit" value="Submit"/><br>
<html:reset value ="Reset"/>
</html:form>
</body>
</html:html>

运行时报如下错误:
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: No getter method for property vResult of bean org.apache.struts.taglib.html.BEAN
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:495)
at org.apache.jsp.input_jsp._jspService(input_jsp.java:75)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
...全文
267 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
weizhihui1213 2006-02-22
呵呵,多谢doway,改正后通过了!
回复
doway 2006-02-22
倒,确实如楼主所说。

vResult 这样的命名不好,我看到的是 JBuilder 2005 都出问题了,在 Bean Properties 页中居然会显示出两个属性:VResult 和 vResult。

改成更合理的名字,如 result 或 varResult 就可以了。我看是开发工具或应用服务器的 bug。
回复
weizhihui1213 2006-02-22
struts是1.0.2版本的,应该不会有问题吧?这个struts是我在建立web module时选择的1.0.2,故自动生成了struts-config.xml
回复
tomuno 2006-02-22
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">

声明版本与classpath的是否冲突
回复
weizhihui1213 2006-02-22
----myActionForm.java--------
package test;

import org.apache.struts.action.*;
import javax.servlet.http.*;

public class myActionForm extends ActionForm {
private String fieldA;
private String fieldB;
private String vResult;

public String getFieldA() {
return fieldA;
}
public void setFieldA(String fieldA) {
this.fieldA = fieldA;
}

public String getFieldB() {
return fieldB;
}
public void setFieldB(String fieldB) {
this.fieldB = fieldB;
}

public String getVResult() {
return vResult;
}
public void setVResult(String vResult) {
this.vResult = vResult;
}

public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
/**@todo: finish this method, this is just the skeleton.*/
return null;
}
public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
}
}
回复
weizhihui1213 2006-02-22
doway(john):但是我仔细查看过actionForm,里面是有getVResult方法的
回复
weizhihui1213 2006-02-22
这是web.xml的内容(建立过程中自动产生):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>struts</display-name>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>application</param-name>
<param-value>ApplicationResources</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-template.tld</taglib-location>
</taglib>
</web-app>
回复
doway 2006-02-22
myActionForm 的 vResult 属性没有 getVResult 方法。
回复
weizhihui1213 2006-02-22
action、actionform都有,见struts-config.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
<form-beans>
<form-bean name="myActionForm" type="test.myActionForm" />
</form-beans>
<global-forwards>
<forward name="input" path="/input.jsp" redirect="true"/>
</global-forwards>
<action-mappings>
<action input="input.jsp" name="myActionForm" path="/myAction" scope="session" type="test.myAction" validate="false" />
</action-mappings>
</struts-config>
这是在建立actionform和action以及jsp时自动产生的
回复
tomuno 2006-02-22
如果请求页面form使用struts标签
那这个action必须配置actionform
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2006-02-22 03:01
社区公告
暂无公告