gpt4 book ai didi

java - 没有为 Action actions.AddExam 和结果输入定义结果

转载 作者:行者123 更新时间:2023-11-30 09:20:56 25 4
gpt4 key购买 nike

我正在输入一些我想添加到数据库中的数据。我通过这样的表格来完成:

<s:form theme="simple" action="addExam">
<div id="reg">
<s:textfield name="exam.name" cssErrorClass="register error"
placeholder="Exam Name" cssClass="register" required="" />
<s:textfield name="exam.minutesAllotted"
placeholder="Minutes Allotted" cssClass="register" required="" />
<s:textfield name="exam.numQuestions"
placeholder="Number Of Questions" cssClass="register" required="" />
<sj:datepicker name="exam.startDate" cssClass="register"
placeholder="Start Date" displayFormat="dd/mm/yy" required="" />
<sj:datepicker name="exam.endDate" cssClass="register"
placeholder="End Date" displayFormat="dd/mm/yy" required="" />
</div>
<!-- Blue Button -->
<s:submit type="button" cssClass="button blue" value="Add" />
</s:form>

struts.xml 的相关部分:

<action name="addExam" class="actions.AddExam">
<result name="success" type="chain">display-exams</result>
<result name="error">/add_exam.jsp</result>
</action>

我的操作如下:

public class AddExam extends ActionSupport{
//Has getter and setter with proper naming convention
private Exam exam;



@Override
public String execute()
{
EntityManagerFactory emf = Persistence.createEntityManagerFactory("ExamModulePu");
EntityManager em = emf.createEntityManager();
ExamService service = new ExamServiceImplementation(em);
Exam examResult = service.createExam(exam);

String result;
if(examResult==null)
{
addFieldError("exam.name", "Duplicate Exam Name");
result = SUCCESS;
}
else
result = ERROR;

em.close();
emf.close();
return result;
}

我的考试实体如下所示:

@Entity
public class Exam implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(unique = true)
private String name;
private int numQuestions;
private int minutesAllotted;
private Date startDate;
private Date endDate;
@OneToMany(mappedBy = "exam", orphanRemoval = true, cascade = CascadeType.ALL)
private List<Question> questionList;
}

当我将数据输入此表单时,出现错误“没有为操作操作定义结果。AddExam 和结果输入”以及堆栈跟踪:

No result defined for action actions.AddExam and result input

com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:275)
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:246)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
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:246)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:546)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

认为这与未正确处理日期输入并设置到我的考试数据成员中有关。我可以从下拉列表中选择一个日期并选择它,但即使我输入了一个无效日期,例如 23/11/51325,它仍然允许我提交并给我同样的错误。可能是我的 Date 变量和输入的格式不匹配?

最佳答案

结果input当对表单的某些验证不正确时触发。您必须将该结果添加到映射的 action 中标记 struts.xml :

<action name="addExam" class="actions.AddExam">
<result name="success" type="chain">display-exams</result>
<result name="error">/add_exam.jsp</result>
<result name="input">/add_exam.jsp</result>
</action>

这样做也许你不需要那个<result name="error"> .

关于java - 没有为 Action actions.AddExam 和结果输入定义结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17184782/

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