Struts未处理的异常 - 没有为动作定义结果 - Struts Spring& hibernate集成

时间:2013-09-12 13:54:03

标签: java spring hibernate jsp struts2

实际上我正在努力实现Struts Spring& Hibernate集成在线考试项目。但是当我在JSP页面中提交值时,它会抛出以下错误:

Struts问题报告

Struts has detected an unhandled exception:

Messages:   
No result defined for action onlineexam.action.RegistrationAction and result 
success

踪迹

No result defined for action onlineexam.action.RegistrationAction and result success
    com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:363)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265)
    com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:251)
    org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:148)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:128)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:164)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:128)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
    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:502)
    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:1023)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    java.lang.Thread.run(Thread.java:724)

我已将RegistrationAction.java附加如下

RegistrationAction.java

public class RegistrationAction extends ActionSupport {

    private UserRegistrationService userRegistrationService;

    public UserRegistrationService getUserRegistrationService() {
        return userRegistrationService;
    }

    public void setUserRegistrationService(
            UserRegistrationService userRegistrationService) {
        this.userRegistrationService = userRegistrationService;
    }

    private String first_Name;
    private String last_Name;
    private String emailid;
    private String passWord;
    private String Gender;
    private int dateofbirth;
    private int phoneNo;
    private float user_experience;

    @ManyToOne(fetch=FetchType.LAZY, targetEntity=UserDetails.class)
    @JoinColumn(name="user_id")
    private int user_id;
    private String addr_line1;
    private String addr_line2;
    private String addr_line3;
    private String city;
    private int zipcode;
    private String state;
    private String country;

    public RegistrationAction() {
    }

// generated getters and setters

    public String SaveUserDetails() {
        String forward = "SUCCESS";

        try {
            UserDetails s = new UserDetails();
            s.setFirst_name(getFirst_Name());
            s.setLast_name(getLast_Name());
            s.setEmail(getEmailid());
            s.setPassword(getPassWord());
            s.setGender(getGender());
            s.setDob(getDateofbirth());
            s.setPhone(getPhoneNo());
            s.setExperience(getUser_experience());

            Set<UserAddress> address = new HashSet<UserAddress>(0);
            setUserAddress(address);
            userRegistrationService.saveUserRegistration(s);

        } catch (Exception ex) {
            forward = "ERROR";
        }
        return forward;   }

    protected void setUserAddress(Set<UserAddress> address) throws Exception {
           UserAddress ad = new UserAddress();
           ad.setAddr_line1(getAddr_line1());
           ad.setAddr_line2(getAddr_line2());
           ad.setAddr_line3(getAddr_line3());
           ad.setCity(getCity());
           ad.setZipcode(getZipcode());
           ad.setState(getState());
           ad.setCountry(getCountry());

           address.add(ad); }
}

MainLayout.jsp

<%@ taglib uri="tiles-jsp.tld" prefix="tiles"%>
<%@ taglib uri="struts-tags.tld" prefix="struts"%>
<html>
<head>
  <meta HTTP-EQUIV="Content-Type" content="text/html" charset="ISO-8859-1">
  <title>ISAS:<tiles:insertAttribute name="title"/></title>
  <style type="text/css">
  </style>
</head>
<body>
    <!-- Header -->
    <tiles:insertAttribute name="header" ignore="true"/>

    <!-- Page Header -->
<div class="noprint">
    <table>
      <tr valign="top">
        <td width=10px></td>
        <td vAlign=top width="99%">         

                <div>
                     <span><tiles:insertAttribute name="pageHeading"/></span>
                </div>
         </td>
       </tr>
    </table>
</div>  
    <!-- Navigation -->
<div>
    <table>
    <tr>
    <td vAlign=top align="center" width="100%"> 
    <tiles:insertAttribute name="nav" ignore="true"/>
    </td>
    </tr>
    </table>    
</div>

    <!-- Body Content -->
    <table>
     <tbody>
      <tr>              
        <td width=10px></td>
        <td vAlign=top align="center" width="99%">  
            <tiles:insertAttribute name="content" ignore="true"/>
        </td>
      </tr>
     </tbody>
    </table>
    <table>
     <tbody>
      <tr>
        <td vAlign=top align="center" width="99%">  
            <br>
        </td>
      </tr>
     </tbody>
    </table>
    <!-- Footer -->
    <tiles:insertAttribute name="footer" ignore="true"/>
</body>
</html>

我不知道问题出在哪里。在运行这个时,它没有在mysql DB中插入值...我对这个话题很新...请帮帮我朋友...无论如何感谢先行朋友...... !!!

1 个答案:

答案 0 :(得分:1)

这是错误的:String forward = "SUCCESS";

正确的字符串“成功”;

String forward = "success";

并且,由于您正在扩展ActionSupport,因此可以使用常量SUCCESS来防止将来出现语法错误。

String forward = SUCCESS;

Struts.xml中必须存在相同的映射。如果你在Struts.xml中放入“SUCCESS”,那就去改变它,以防止将来出现问题......

P.S:同样的“错误”应该是“错误”。