How to Solve Tomcat Error: Could not resolve view with name ‘xxx/xxxxxxx‘ in servlet with

Click the control to not receive the returned JSON object, Tomcat reports an error.

reason:

Because the return information is a JSON object, the annotation added to the entry class where the controller method is located is: @ controller

The @controller is not suitable for returning JSON content

Method 1: change the @ controller annotation to @restcontroller without affecting the use of other methods

Method 2: add @ ResponseBody annotation to the method that needs to request to return the JSON object

Some of the other methods in the class of this method in the project return to the specified page, so @restcontroller cannot be used to replace @ controller directly, so method 2 is adopted to solve the problem.

The difference between @controller and @restcontroller is as follows

@Restcontroller is a stereotype annotation that combines @ ResponseBody and @ controller.
it means:
@restcontroller annotation is equivalent to the combined function of @ ResponseBody + @controller.

1) If you only use @restcontroller to annotate the controller, the methods in the controller cannot return the JSP page, the configured view parser internalresourceviewresolver does not work, and the returned content is the content in return.

For example, if you should go to the success.jsp page, success.jsp will be displayed

2) If you need to return to the specified page, you need to use @ controller with the view parser internalresourceviewresolver
3) if you need to return JSON, XML or custom media type content to the page, you need to add @ ResponseBody annotation to the corresponding method

Read More: