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:
- [Solved] Circular view path [index]: would dispatch back to the current handler URL [] again. Che
- [Solved] Tomcat runs JavaWeb servlet Error 404
- [Solved] IDEA2020 Error: Cannot resolve symbol ‘Servlet‘
- [Solved] javax.servlet.ServletException: Servlet[springmvc] Servlet.init()
- How to Solve JAR pack error: Error resolving template [/userInfo], template might not exist or might not be accessib
- How to Solve Springboot Upload Files Error: The field XXX exceeds its maximum permitted size of 1048576 bytes
- How to Solve Flick operate Error: not serialized
- Resolve warning: could’t clear Tomcat cache java.lang.NoSuchFieldException: resourceEntries
- [Solved] Docker Run Tomcat Error: Cannot find /usr/local/tomcat/bin/setclasspath.sh
- How to Solve SSM JSON Chinese Messy Code Issue
- How to Solve Image Upload Error: Uncaught (in promise) DOMException: Failed to execute ‘put‘ on ‘IDBObjectStore‘
- [Solved] IDEA Maven Error: Cannot resolve xxx & Maven Dependencies Error
- How to Solve classnotfoundexception error in spark without Hadoop runtime
- How to Solve JUnit Debugging initializationerror ERROR
- How to Solve Mybatis error: invalid bound statement (not found)
- How to Solve SQL comments error in the mybatis query
- How to Solve Error executing DDL in JPA
- JAVA Code Start Exception Error View Does Not Exsit [Solved]
- How to Solve zipkin Install Error in Windows
- Continuous Error 404 in servlet operation [How to Solve]