gpt4 book ai didi

java - 如何向 Struts 2 添加 Action

转载 作者:搜寻专家 更新时间:2023-11-01 03:10:01 25 4
gpt4 key购买 nike

我对 Struts 2 上的操作有疑问。

假设我有一个带有操作 "save"

的表单

我已经在我的 struts.xml 上将该操作映射到某种方法,如下所示:

<action name="save" class="actions.agenda" method="save">
<result name="success">/agenda/success.jsp</result>
</action>

在我的 Action 类中,我使用 execute 在表单中加载一些参数,因此我创建了保存新条目的方法:

public String save(){
///Logic here
dao.create(entry)
return SUCCESS;
}

问题是我遇到了这个错误:

严重:找不到操作或结果

有人可以给我关于这个问题的线索:)?

web.xml

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<filter>
<filter-name>springOpenEntityManagerInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
<init-param>
<param-name>entityManagerFactoryBeanName</param-name>
<param-value>entityManagerFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>springOpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<session-config>
<session-timeout>
30
</session-timeout>
</session-config>

.....

</web-app>

我在名为“Actions.xml”的单独 xml 上执行(保存)操作,并且包含在 struts.xml 中

堆栈跟踪

Stacktraces
No result defined for action actions.agenda and result input

com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:376)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:278)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:432)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
com.sun.grizzly.ContextTask.run(ContextTask.java:71)
com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
java.lang.Thread.run(Thread.java:722)

其他操作正常。

最佳答案

您实际收到的投诉是 No result defined for action actions.agenda and result input .基本上,这意味着某些原因导致 Struts 认为您正在向其中一个属性提供无效数据(或者验证方法添加了一个字段/操作错误)。

例如也许你有一个 setter,它接受一个整数,你正在将一个非整数值传递给它,类似的东西。因为它无法将提供的值转换为适合 setter 的值,所以它会提示。

这会导致操作返回“INPUT”值,您没有为其定义任何结果。通常这里要做的是返回保存“输入”结果之前呈现的相同表单,作为普通的 Struts 2 标签,如 <s:textfield><s:select>将在相应字段上方显示字段错误。

关于java - 如何向 Struts 2 添加 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12904966/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com