springmvc显示页面问题

时间:2016-04-23 17:39:17

标签: java spring spring-mvc

我一直在努力设置一个mvc项目,而且我已经尝试显示welcome.html页面一段时间没有任何成功。

Below is the structure of the project

以上是项目的结构

我的家庭控制器

04-23 17:40:35.938 14196-14196/com.myapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                             Process: com.myapp, PID: 14196
                                                             java.lang.StackOverflowError: stack size 8MB
                                                                 at android.animation.PropertyValuesHolder.nCallFloatMethod(Native Method)
                                                                 at android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:39)
                                                                 at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1298)
                                                                 at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:956)
                                                                 at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:602)
                                                                 at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:550)
                                                                 at android.animation.ValueAnimator.start(ValueAnimator.java:1039)
                                                                 at android.animation.ValueAnimator.start(ValueAnimator.java:1050)
                                                                 at android.animation.ObjectAnimator.start(ObjectAnimator.java:829)
                                                                 at com.myapp.customshapes.SendingProgressView.setCurrentProgress(SendingProgressView.java:222)
                                                                 at android.animation.PropertyValuesHolder.nCallFloatMethod(Native Method)
                                                                 at android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:39)
                                                                 at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1298)
                                                                 at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:956)
                                                                 at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:602)
                                                                 at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:550)
                                                                 at android.animation.ValueAnimator.start(ValueAnimator.java:1039)
                                                                 at android.animation.ValueAnimator.start(ValueAnimator.java:1050)
                                                                 at android.animation.ObjectAnimator.start(ObjectAnimator.java:829)
                                                                 at com.myapp.customshapes.SendingProgressView.setCurrentProgress(SendingProgressView.java:222)
                                                                 at android.animation.PropertyValuesHolder.nCallFloatMethod(Native Method)
                                                                 at android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:39)
                                                                 at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1298)
                                                                 at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:956)
                                                                 at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:602)
                                                                 at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:550)
                                                                 at android.animation.ValueAnimator.start(ValueAnimator.java:1039)
                                                                 at android.animation.ValueAnimator.start(ValueAnimator.java:1050)
                                                                 at android.animation.ObjectAnimator.start(ObjectAnimator.java:829)
                                                                 at com.myapp.customshapes.SendingProgressView.setCurrentProgress(SendingProgressView.java:222)
                                                                 at android.animation.PropertyValuesHolder.nCallFloatMethod(Native Method)
                                                                 at android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:39)
                                                                 at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1298)
                                                                 at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:956)
                                                                 at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:602)
                                                                 at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:550)
                                                                 at android.animation.ValueAnimator.start(ValueAnimator.java:1039)
                                                                 at android.animation.ValueAnimator.start(ValueAnimator.java:1050)
                                                                 at android.animation.ObjectAnimator.start(ObjectAnimator.java:829)
                                                                 at com.myapp.customshapes.SendingProgressView.setCurrentProgress(SendingProgressView.java:222)
                                                                 at android.animation.PropertyValuesHolder.nCallFloatMethod(Native Method)
                                                                 at android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:39)
                                                                 at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1298)
                                                                 at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:956)
                                                                 at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:602)
                                                                 at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:550)
                                                                 at android.animation.ValueAnimator.start(ValueAnimator.java:1039)
                                                                 at android.animation.ValueAnimator.start(ValueAnimator.java:1050)
                                                                 at android.animation.ObjectAnimator.start(ObjectAnimator.java:829)
                                                                at com
04-23 17:40:36.068 14196-14196/com.myapp E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!
04-23 17:40:36.068 14196-14196/com.myapp E/AndroidRuntime: Error reporting crash
                                                             android.os.TransactionTooLargeException
                                                                 at android.os.BinderProxy.transactNative(Native Method)
                                                                 at android.os.BinderProxy.transact(Binder.java:496)
                                                                 at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:4164)
                                                                 at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:89)
                                                                 at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.uncaughtException(CrashlyticsUncaughtExceptionHandler.java:249)
                                                                 at com.myapp.activities.Application$1.uncaughtException(Application.java:56)
                                                                 at com.flurry.sdk.mc.b(SourceFile:96)
                                                                 at com.flurry.sdk.mc.b(SourceFile:19)
                                                                 at com.flurry.sdk.mc$a.uncaughtException(SourceFile:107)
                                                                 at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
                                                                 at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)

作品-servlet.xml中

        /**
 * 
 */
package com.knockknocks.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

    /**
     * @author vimal
     *
     */
    @Controller

    public class HomeController {
        @RequestMapping(value="/welcome")
        public ModelAndView home(){
            String message = "This is your home";
            System.out.println(123456);
             return new ModelAndView("welcome", "message", message);
        }

    }

的web.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="com.knockknocks.controller" />
<mvc:annotation-driven />
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

pom文件

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Knockknocks</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>works</servlet-name>
    <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>works</servlet-name>
    <url-pattern>/welcome.jsp</url-pattern>
    <url-pattern>/welcome.html</url-pattern>
    <url-pattern>*.html</url-pattern>
  </servlet-mapping>
</web-app>

日志

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>KnockKnocks</groupId>
  <artifactId>KnockKnocks</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>


    </plugins>
  </build>
  <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.3</version>
        </dependency>
    </dependencies>
</project>

当我尝试压缩网址http://localhost:8080/KnockKnocks/welcome.html时,我出现错误HTTP状态404 - /KnockKnocks/welcome.html。

我很感激有人可以帮助我。

此致

4 个答案:

答案 0 :(得分:2)

使用:

<mvc:annotation-driven />

在你的works-servlet.xml

它将您的Spring上下文设置为允许向控制器分派请求。

我希望这会对你有所帮助。

答案 1 :(得分:2)

您的示例 works.servlet 显示:

<context:component-scan base-package="com.knockknock.controller" />

但HomeController类中显示的包是:

package com.knockknocks.controller;

你需要那些匹配。前者错过了&#39;

答案 2 :(得分:1)

您的班级HomeController并未映射任何网址:

@Controller
public class HomeController {

    @RequestMapping(name = "/welcome")
    public ModelAndView home(){
        String message = "This is your home";
        return new ModelAndView("welcome", "message", message);
    }
}

您必须将@RequestMapping(name = "/welcome")更改为@RequestMapping(value = "/welcome") 正如document提供的那样,@RequestMapping注释的选项元素:
name: String - 为此映射指定名称 value: String[] - 此注释表示的主要映射 ...

答案 3 :(得分:1)

我有另一个想法。检查您的.jsp是否位于正确的位置并且名称正确。也就是说,你的WEB-INF / jsp目录中有welcome.jsp吗?还要查看404页面上的特定消息,以查看它未找到的特定文件,并检查该目录位置中是否确实包含该文件。