Tag Archives: SpringMVC

[Solved] Spring MVC cross server upload error: returned a response status of 405 method not allowed

The error of uploading picture newspaper 405 across servers is because Tomcat is read-only by default. We turn off read-only and allow adding files instead.

Solution: Find the web.xml file in the tomcat installation directory, open it and add the following code in the servlet:

<!– Allow Tomcat server to add files — >

< init-param>
< param-name> readonly
< param-value> false

Spring MVC: How to Solve Chinese garbled code Issue

The parameters of spring MVC receiving get requests are not necessarily garbled

tomcat 8.xx Before the encoding default is iso After the encoding default is utf-8

Spring MVC receives post requests without coding rules, so it will be garbled

    web.xml   add CharacterEncodingFilter

      <filter>
        <filter-name>charset</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
          <param-name>encoding</param-name>
          <param-value>UTF-8</param-value>
        </init-param>
      </filter>
      <filter-mapping>
        <filter-name>charset</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>

Spring MVC upload file error string cannot be converted to multipartfile

Recently, I encountered a type receiving error when uploading with springmvc. The input tag of file type is set in the JSP form, but an error is reported when receiving with multipartfile in springmvc, which roughly means that string convert multipartfile has an error. Finally, I know that I am using form submission. The enctype attribute in the form must be set to enctype = “multipart/form data”, Because only this attribute means that the file file is uploaded, and I didn’t write it

The enctype in the form has three attributes: 1. Application/x-www-form-urlencoded. 2、multipart/form-data。   3、text/plain

1: Encode all characters before encoding, including special characters, convert spaces to “+” symbols, and special characters to ASCII hex values. It is also the default setting for form

2: No character encoding. This value must be used when using a form containing a file upload control, and the file will be read in a binary stream

3: Spaces are converted to a “+” plus sign, but special characters are not encoded

 

HTTP status 500 – servlet. Init () [How to Solve]

HTTPStatus500-Servlet.init()forservletspringmvcthrewexception
typeExceptionreport
messageServlet.init()forservletspringmvcthrewexception
descriptionTheserverencounteredaninternalerrorthatpreventeditfromfulfillingthisrequest.
exception
javax.servlet.ServletException:Servlet.init()forservletspringmvcthrewexception
	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
	org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
	org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	java.util.concurrent.ThreadPoolExecutor.runWorker(UnknownSource)
	java.util.concurrent.ThreadPoolExecutor$Worker.run(UnknownSource)
	org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	java.lang.Thread.run(UnknownSource)
rootcause
org.springframework.beans.factory.CannotLoadBeanClassException:Cannotfindclass[org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping.class]forbeanwithname'org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping.class#0'definedinServletContextresource[/WEB-INF/springmvc-servlet.xml];nestedexceptionisjava.lang.ClassNotFoundException:org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping.class
	org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1262)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576)
	org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1331)
	org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:897)
	org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:588)
	org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925)
	org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472)
	org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
	org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
	org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
	org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
	org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
	org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
	javax.servlet.GenericServlet.init(GenericServlet.java:158)
	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
	org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
	org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	java.util.concurrent.ThreadPoolExecutor.runWorker(UnknownSource)
	java.util.concurrent.ThreadPoolExecutor$Worker.run(UnknownSource)
	org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	java.lang.Thread.run(UnknownSource)
rootcause
java.lang.ClassNotFoundException:org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping.class
	org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1858)
	org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1701)
	org.springframework.util.ClassUtils.forName(ClassUtils.java:258)
	org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:417)
	org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1283)
	org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1254)
	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576)
	org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1331)
	org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:897)
	org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:588)
	org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925)
	org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472)
	org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
	org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
	org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
	org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
	org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
	org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
	javax.servlet.GenericServlet.init(GenericServlet.java:158)
	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
	org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
	org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	java.util.concurrent.ThreadPoolExecutor.runWorker(UnknownSource)
	java.util.concurrent.ThreadPoolExecutor$Worker.run(UnknownSource)
	org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	java.lang.Thread.run(UnknownSource)
noteThefullstacktraceoftherootcauseisavailableintheApacheTomcat/7.0.68logs.





Solution.
1 web.xml or other xml configuration class-name, after not in the appearance of .class, only the name can be.
2. remove tomcat server, and then create a new server.
3. redeploy, success.
PS: The encoding of jsp file is utf-8
In addition, there are several errors, the main reason is that the code is not standardized, there are errors, you should carefully check their code, correct the bugs basically nothing wrong

HTTP status 405 – request method ‘get’ not supported using springmvc

Don’t panic in case of data tilt, teach you to easily obtain the slope of table tilt>>>

The get method is not supported. The reason why I made a mistake is that in JSP, I want hyperlink a to be submitted by post, but there was an error when writing JS code here

<script type="text/javascript">
    $(function(){
        $(".delete").click(function(){
            var href = $(this).attr("href");
            $("form").attr("action",href).submit();
            //alert("ok");
            return false;
        })        
    })
</script>

JS code itself is not wrong, the error is the configuration of hyperlinks

<form action="" method="post">
        <input type="hidden" name="_method" value="delete" />
    </form>

    <a href="emp/${emp.id%20}">Delete</a>

The above is the JSP code, and the hyperlink A is missing a class = “delete”

That’s right

<form action="" method="post">
        <input type="hidden" name="_method" value="delete" />
    </form>

    <a class="delete" href="emp/${emp.id%20}">Delete</a>