Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java方法未返回正确的类型_Java_Jsp_Methods_Return - Fatal编程技术网

java方法未返回正确的类型

java方法未返回正确的类型,java,jsp,methods,return,Java,Jsp,Methods,Return,我在一个类中有一个方法,假设它在按下“下一步”按钮后返回一个jsp文件。但它只是擦除当前页面中的数据并返回当前页面 这就是方法 @RequestMapping(value = "/addQuestion", method = RequestMethod.POST) public String addQuestion(Model model, @RequestParam(value="question", required = true) String theQuestion ,

我在一个类中有一个方法,假设它在按下“下一步”按钮后返回一个jsp文件。但它只是擦除当前页面中的数据并返回当前页面

这就是方法

@RequestMapping(value = "/addQuestion", method = RequestMethod.POST)
        public String addQuestion(Model model, @RequestParam(value="question", required = true)  String theQuestion , @RequestParam(value="questionId", required = true)  Integer questionId, @RequestParam(value="category", required = true)   String category, @RequestParam(value="correctAnswer", required = true)   String correctAnswer) throws SQLException{
                ViewController viewController = new ViewController();
                viewController.createQuestion(questionId, theQuestion, category, correctAnswer);
                model.addAttribute("question", new Question());
                return "qFour";
        }

它应该返回qFour.jsp,但它只返回addQuestion.jsp,这是它当前所在的页面

您可以从下面的方法返回
ModelAndView

@RequestMapping(value = "/addQuestion", method = RequestMethod.POST)
    public ModelAndView addQuestion(Model model, @RequestParam(value="question", required = true)  String theQuestion , @RequestParam(value="questionId", required = true)  Integer questionId, @RequestParam(value="category", required = true)   String category, @RequestParam(value="correctAnswer", required = true)   String correctAnswer) throws SQLException{
        ViewController viewController = new ViewController();
        viewController.createQuestion(questionId, theQuestion, category, correctAnswer);

        return return new ModelAndView("qFour", "question", new Question());
    }

由于您没有提供配置文件内容,因此很难确切地说出需要更改的内容。但我认为,出于您的目的,addQuestion方法的返回类型必须是ModelAndView,而不是String。请尝试使用以下返回语句:

return new ModelAndView("qFour.jsp");

qFour
返回正确吗?返回后我放的东西没有区别。i、 e.返回“qFour”返回“qOne”返回“qFive”。预期的jsp不符合,您的语法是正确的,因此存在其他一些问题。我还可以提供哪些代码来帮助我找到问题的解决方案?首先,尝试调试您的代码,并找出是否调用了您的
addQuestion
方法?谢谢,现在将尝试。假设你也只想返回一次,是吗?不,不幸的是,它仍然在做同样的事情。在addQuestion.jsp中有一个action=“addQuestion”的表单,它应该调用这个表单并将内容添加到数据库中。也许错误就在那里……您使用的是哪个版本的spring?是否调用了您的
addQuestion
方法?我认为spring版本3.2.7。是否有一种简单的方法可以转换为3.1.1?