【问题标题】:Controller doesn't response to the button on the website控制器不响应网站上的按钮
【发布时间】:2014-09-26 16:39:43
【问题描述】:

我是前端新手,我的网站上有一个基于 thymeleaf 的 div 块,我在其中创建了一个按钮,这是 html 代码,请关注最后三行的按钮,

<form th:action="@{/quiz/nextQuestion}" th:object="${answeredQuestion}" method="post">
    <div class="panel-body">
      <h3 th:text="${questionStem}">which is the best answer</h3>
      <div class="skin skin-square">
        <div class="skin-section">        
          <ul class="list">
            <li th:each="option,rowStat : ${options}">
              <input tabindex="11" type="radio" th:id="${rowStat.index}" name="square-radio"></input>
              <label th:for="${rowStat.index}" th:text="${option.optionString}" >option 1</label>
            </li>
          </ul>
        </div>          
        <script>
            $(document).ready(function(){
              $('.skin-square input').iCheck({
                checkboxClass: 'icheckbox_square-blue',
                radioClass: 'iradio_square-blue',
                increaseArea: '20%'
              });
            });
        </script>
      </div>
    </div>
    <div class="layout-onright-30">
        <button type="button" class="btn default" action="submit">Next One</button>
    </div>
</form>

下面是我的控制器,

@Controller
@EnableAutoConfiguration
@RequestMapping("/quiz")
@Import({ QuizServiceImpl.class, QuestionServiceImpl.class })
public class ExamController {
    private static UUID testVariable = null;
    @RequestMapping(value = "/nextQuestion", method = RequestMethod.POST)
    public ModelAndView doNextQuestion(@ModelAttribute("answeredQuestion") AnsweredQuestion answeredQuestion) {
        System.out.println("run in next ques");
        Question question = quizService
                .getNextQuestion(null, testVariable);
        System.out.println(question.toString());
        ModelAndView modelAndView = new ModelAndView("examination");
        ChoiceQuestion choiceQuestion = (ChoiceQuestion) question;
        modelAndView.addObject("questionStem", choiceQuestion.getQuestionStem());
        modelAndView.addObject("options", choiceQuestion.getOptions());
        return modelAndView;        
    }
}

补充信息,answeredQuestion 是一个没有任何方法或成员的空类。

问题是,当我点击按钮Next One时,控制器没有任何响应,我使用的是spring boot,我确定服务和控制器都启动了。

谁能帮帮我?
非常感谢。

【问题讨论】:

  • UI 中是否发生了某些事情(例如提交表单)?您可以启用日志记录并查看表单提交(如果发生)是否能够匹配适当的控制器?一旦您确定请求是否正在执行以及它的去向,您也许可以自己解决这个问题。
  • 谢谢@prabugp,对我很好,听从了你的建议,我找到了没有提交的答案。

标签: java jquery html spring-mvc controller


【解决方案1】:

我在 html 中犯了一个错误,我认为我们遵循了@prabugp 的建议。

换行:

<button type="button" class="btn default" action="submit">Next One</button>

到:

<button class="btn default" type="submit">Next One</button>

它有效。打错字了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-08
    • 1970-01-01
    • 2013-08-20
    • 1970-01-01
    相关资源
    最近更新 更多