成功的formSubmit转到错误页面404

时间:2017-04-05 14:56:05

标签: javascript jquery ajax hibernate spring-mvc

我有一个简单的模态反馈表单,从我的主页面点击按钮弹出。我将表单值传递给控制器​​并使用Hibernate插入值。成功插入DB值后,我希望我的模态关闭一些自定义消息,以显示给用户。但我的问题是,它将我重定向到另一个页面error.jsp与404错误。也看起来它没有返回ajax调用成功。我不确定我做错了什么。 请帮忙。 下面是我的控制器,DAO,JS,JSP代码

JSP代码

          <p><button id="modal_open" class="inner rotate">Site   Feedback</button></p>

          <div id="modal_wrapper">
          <div id="modal_window">

          <div style="text-align: right;"><a id="modal_close" href="#">close   <b>X</b></a></div>

          <p><Strong>We'd love your feedback.</Strong><br></p>

          <p>Your feedback will help us improve your experience. To protect your privacy, please do not enter personal or account information.</p>

          <form id="modal_feedback" method="POST" action="" accept-charset="UTF-8" >
          Your Name :<br>
          <input type="text" name="name" id="name" value=""><span></span><br>
          <div class="feedback">
          <div class="feedbackCl" >
          <input id="overall_0" name="overall" id="overall" type="radio" value="1" tabindex="0" aria-describedby="o1-l">
          <label for="overall_0" class="labelClass">
          <span class="sight">— —</span>
          <span class="screen_reader" id="o1-l">Poor</span>
         </label>
       </div>
       <div class="feedbackCl">
    <input id="overall_1" name="overall"  id="overall" type="radio" value="2" tabindex="0" aria-describedby="o2-l">
    <label for="overall_1" class="labelClass">
      <span class="sight">—</span>
      <span class="screen_reader" id="o2-l">Fair</span>
    </label>

  </div>
  <div class="feedbackCl">
    <input id="overall_2" name="overall" id="overall" type="radio" value="3" tabindex="0" aria-describedby="o3-l">
    <label for="overall_2" class="labelClass">
      <span class="sight">+ —</span>
      <span class="screen_reader" id="o3-l">Good</span>
    </label>
  </div>
   <div class="feedbackCl">
    <input id="overall_3" name="overall" id="overall" type="radio" value="4" tabindex="0" aria-describedby="o4-l">
    <label for="overall_3" class="labelClass">
      <span class="sight">+</span>
      <span class="screen_reader" id="o4-l">Very Good</span>
    </label>
  </div>
  <div class="feedbackCl">
    <input id="overall_4" name="overall" id="overall" type="radio" value="5" tabindex="0" aria-describedby="o5-l">
    <label for="overall_4" class="labelClass">
      <span class="sight">+ +</span>
      <span class="screen_reader" id="o5-l">Excellent</span>
    </label>
  </div>
  </div>
  <br>
  <span><br></span><br>
  <textarea style="overflow-x: hidden;" id="gBann" name="message" maxlength="1000" rows="4" cols="80" placeholder="How can we improve our site? Please share your suggestions." onKeyUp="toCount('gBann','uBann','{CHAR} characters left',1000);" ></textarea><br>
  <span id="uBann" class="minitext" style="text-align: right;">1000 characters left</span><br> 
  <input type="submit" name="feedbackForm" class="buttonFb button1" value="Submit" id="submit_btn">
</form>

JS代码

        document.getElementById("modal_feedback").addEventListener("submit",    function(e) {
        var form = this;
        var name = form.name.value;
        var rating = form.overall.value;
        var msg = form.message.value;
        if(name == "") {
          alert("Please enter your Name");
          form.name.focus();
          e.preventDefault();
          } else if(rating == "") {
          alert("Please select a rating");
          form.overall[0].focus();
          e.preventDefault();
          } else if(msg == "") {
          alert("Please enter your comment in the Message box");
          form.message.focus();
          e.preventDefault();
          }
          $.ajax({
             type: "POST",
             url: "feedbackData.htm?ratingId="+rating+"&msg="+msg,
             success: function(response) {
             if(response == 'Y'){
             $('#contact_form').html("<div id='message'></div>");
             $('#message').html("<h2>FeedbackForm Submitted!</h2>")
             .append("<p>We will be in touch soon.</p>")
             .hide()
             .fadeIn(1500, function() {
                 $('#message').append("<img id='checkmark' src='images/icon_check.png' />");
               });
              }
             }
           });
          return false;

      }, false);

         FeedbackController code

         @Controller
         public class FeedbackController {

        @Autowired
        private FeedbackService feedbackService;

        private static final Logger logger = Logger.getLogger(FeedbackController.class);

        @RequestMapping(value = "/feedbackData")
        public @ResponseBody String getFeedbackData(String ratingId, String msg) throws UnsupportedEncodingException{
         System.out.println("Inside FeedbackController..");
        try{
           feedbackService.updateFeedback(ratingId,msg);
           return "Y";
        }catch(Exception e)
        {
          logger.error("Exception in Login :" + e);
          return "N";
         }
       }

     }

FeedbackDAO实施

      @Repository("feedbackDao")
      public class FeedbackDaoImpl implements FeedbackDao{

      @Autowired
      private SessionFactory sessionFactory;    

      @Override
      public int insertFeedback(String ratingId, String msg) {
      int status = 0;

      Session sess = sessionFactory.openSession();
        Transaction tx = null;
        try {
            tx = sess.beginTransaction();
            Feedback fbObj = new Feedback();
            fbObj.setFbRatingId(Integer.parseInt(ratingId));
            fbObj.setFbSuggestion(msg);
            fbObj.setFbTopicId(null);
            fbObj.setUserInfo("");
            sess.save(fbObj);
            tx.commit();
            status  = 1;
        } catch (HibernateException e) {
            System.out.println("Exception in feedback record :" + e);
            if (tx != null) {
                tx.rollback();
            }
        } finally {
            sess.close();
        }        
     return status;
}

 }

错误跟踪

         Inside FeedbackController..
         Hibernate: insert into feedback (fb_rating_id, fb_suggestion,  fb_topic_id, user_info) values (?, ?, ?, ?)
         Apr 05, 2017 12:12:03 PM org.apache.catalina.core.ApplicationDispatcher invoke
             SEVERE:Servlet.service() for servlet jsp threw exception
             javax.servlet.ServletException:      File [/WEB-INF/views/error.jsp] not found
            at                    org.apache.jasper.servlet.JspServlet.handleMissingResource(JspServlet.java:418)
            at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
           at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at              org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:716)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:523)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:229)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1519)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1475)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
     at java.lang.Thread.run(Thread.java:745)

       Apr 05, 2017 12:12:03 PM org.apache.catalina.core.StandardWrapperValve invoke
       SEVERE: Servlet.service() for servlet [tdp] in context with path              [/TDP] threw exception [File [/WEB-INF/views/error.jsp] not found] with root cause
       javax.servlet.ServletException: File [/WEB-INF/views/error.jsp] not found
        at org.apache.jasper.servlet.JspServlet.handleMissingResource(JspServlet.java:418)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)

0 个答案:

没有答案