springmvc osx windows servlet maven

时间:2016-03-05 23:57:47

标签: java maven spring-mvc tomcat servlets

我有一个webapp。它在iosx上工作正常。但是,如果我将项目(mavenproject)导入我的虚拟机到Windows 10(使用git克隆并使用mavenproject导入到eclipse中)。如果我想将某些内容上传到服务器,则会收到错误。"请求的资源不可用。"要查看上传页面,我得到了以下控制器:

@RequestMapping(value = "/erstellen", method = RequestMethod.GET)
    public String zeigErstellenForm() {
        System.out.println("im here");
        return "dateien_upload_erstellen";
    }

可以看到上传页面,所以我猜这个函数被调用了,但是它不打印"我在这里"。我无法理解最新情况。

浏览器出错:

  

输入例外报告

     

消息请求处理失败;嵌套异常是   显示java.lang.NullPointerException

     

description服务器遇到阻止它的内部错误   完成此请求。

     

exception org.springframework.web.util.NestedServletException:Request   处理失败;嵌套异常是java.lang.NullPointerException     org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:981)     org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)     javax.servlet.http.HttpServlet.service(HttpServlet.java:648)     org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

     

root cause java.lang.NullPointerException     de.bla.blabla.Services.OrdnerErstellen.namePruefen(OrdnerErstellen.java:52)     de.bla.blabla.Services.OrdnerErstellen.randomName(OrdnerErstellen.java:33)     de.bla.blabla.Services.OrdnerErstellen。(OrdnerErstellen.java:17)     de.bla.blabla.Controller.DateiUploadController.save(DateiUploadController.java:52)     sun.reflect.NativeMethodAccessorImpl.invoke0(原生方法)     sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)     sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)     java.lang.reflect.Method.invoke(未知来源)     org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:178)     org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:444)     org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:432)     org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)     org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)     org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)     org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)     javax.servlet.http.HttpServlet.service(HttpServlet.java:648)     org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

日食错误:

  

SCHWERWIEGEND:Servlet.service()用于上下文中的servlet [test]   path [/ testMaven]抛出异常[请求处理失败;   具有根本原因的嵌套异常是java.lang.NullPointerException]   java.lang.NullPointerException at   de.bla.blabla.Services.OrdnerErstellen.namePruefen(OrdnerErstellen.java:52)     在   de.bla.blabla.Services.OrdnerErstellen.randomName(OrdnerErstellen.java:33)     在   de.bla.blabla.Services.OrdnerErstellen。(OrdnerErstellen.java:17)     在   de.bla.blabla.Controller.DateiUploadController.save(DateiUploadController.java:52)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at   sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at   java.lang.reflect.Method.invoke(未知来源)at   org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:178)     在   org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:444)     在   org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:432)     在   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)     在   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)     在   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)     在   org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:648)at   org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:729)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)     在   org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)     在   org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:672)     在   org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1500)     在   org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run(NioEndpoint.java:1456)     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)     at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)     在   org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)     在java.lang.Thread.run(未知来源)

我用:

  • tomcat 8

的servlet:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<context:component-scan base-package="de.bla.blabla.Controller"/>


 <bean id="multipartResolver"
  class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>

<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/"/>

  <bean id="jspViewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
  </bean>
</beans>

的web.xml:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
          http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">  <display-name>test</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>test</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
        <servlet-name>test</servlet-name>
        <url-pattern>*.html</url-pattern>
        <url-pattern>/download</url-pattern>
        <url-pattern>/read</url-pattern>
    </servlet-mapping>

</web-app>

项目中没有错误。我清理了所有更新的maven等。

1 个答案:

答案 0 :(得分:0)

您无法在JSP中显示sysout消息!

在您的webapp的WEB-INF/jsp目录中,创建一个文件index.jsp并在这些JSP中写入您的helloWorld消息。

除非你遗漏了别的东西,否则它会有效。

或者如果您想在控制器中使用模型,如下所示:

ModelAndView mav = new ModelAndView();
mav.addObject("message", "hello world");
return mav;

对于你的nullpointer异常,我将尝试使用你的eclipse平台进行远程调试,并在这些行中做一些断点:

de.bla.blabla.Services.OrdnerErstellen.namePruefen(OrdnerErstellen.java:52)

at de.bla.blabla.Services.OrdnerErstellen.randomName(OrdnerErstellen.java:33)

at de.bla.blabla.Services.OrdnerErstellen.(OrdnerErstellen.java:17)

at de.bla.blabla.Controller.DateiUploadController.save(DateiUploadController.java:52)