Tag Archives: JumpMVC

Spring MVC 406 status code / could not find acceptable representation

 
Jackson-core-asl-1.9.12.jar Jackson-mapper-asl-1.9.12.jar
The test is not for this error and does not have to rely on the two JARs.
The following configuration returns data normally
 
pom.xml
 

        <!-- Jackson JSON Processor -->

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson.version}</version>
        </dependency>

 
 
For springMvc. In the XML
 
 

    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="false">
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html;charset=utf-8</value>
                        <value>text/xml;charset=utf-8</value>
                        <value>text/plain;</value>
                        <value>text/json;charset=utf-8</value>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
        </mvc:message-converters>
    </mvc:annotation-driven>

 
 
 
 
 
In the Controller
 

  @RequestMapping(value = "checkLogin", method = RequestMethod.POST)
    @ResponseBody
    public ResultDto checkLogin(String name, String password, int role) {

        return loginService.checkLogin(name, password, role);
    }

 
 
 
——————————————————————————-
The ResultDTO object is missing some of the GET methods, causing an error in formatting the JSON object.
Remove the above two JARs and test with the GET method of the returned object, reporting 406 error code.
The debug code in ServletInvocableHandlerMethod. Catch exceptions in the class “Could not find acceptable representation.” ”
After adding the get method, the test returns the JSON character of the object normally
 
 

public class ResultDto {

    private boolean succeed;
    private Object data;

    public ResultDto(boolean succeed) {
        this.succeed = succeed;
    }

    public ResultDto(boolean succeed, Object data) {
        this.succeed = succeed;
        this.data = data;
    }

/*
    public boolean isSucceed() {
        return succeed;
    }

    public Object getData() {
        return data;
    }
*/

    public void setSucceed(boolean succeed) {
        this.succeed = succeed;
    }

    public void setData(Object data) {
        this.data = data;
    }
}

 
 

 

About content type ‘multipart / form data…’ not support

Project Scenario:
on using springcloud, the gateway jump specifies that the service displays an error message


Problem description:

Content type 'multipart/form-data;boundary=----WebKitFormBoundaryek7Ljn5odm2QALlC;charset=UTF-8' not supported

Reason analysis:
this is because the requested parameter is content-type:multipart/form-data, which is submitted as a form. Therefore, the problem occurs on the parameter, and the annotation on the parameter can be removed (it only needs to be in the parameter form of springmvc)

Solution in idea java.lang.ClassNotFoundException : org.springframework.web . context.ContextLoaderListener

Reference blog: IDEA development in Java. Lang. ClassNotFoundException: org. Springframework. Web. Context. The ContextLoaderListener error solution


Have a problem
In the process of writing a simple SpringMVC project, I tried to start the project with Tomcat, but found the following errors:

java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener

Simply put, the ContextLoaderListener class cannot be found. The strange thing about
is that the SpringMVC project that I wrote before doesn’t have similar problems. ┍ ┑ ( ̄ Д  ̄)


The solution
After asking baidu, I was told to add Available Elements to the Artifact.
click File - & gt; Project Structure-> Artifacts, right-click the project name in Available Elements, and select Put into Output Root.

Then restart Tomcat, you will be able to access the page correctly! O (≧ ヾ del ≦ *)