私はmvcプロジェクトを設定するためにしばらくの間苦労していましたが、私はwelcome.htmlページを何も成功させずに表示しようとしていました。springmvcの表示ページの問題
上記は、プロジェクトの構造
私にHomeController
/**
*
*/
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);
}
}
作品-servlet.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>
web.xmlの
0でありますポンポンファイル
<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>
ログイン
Apr 23, 2016 9:23:04 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Apr 23, 2016 9:23:05 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Apr 23, 2016 9:23:05 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'works'
Apr 23, 2016 9:23:05 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'works': initialization started
Apr 23, 2016 9:23:05 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'works-servlet': startup date [Sat Apr 23 21:23:05 MUT 2016]; root of context hierarchy
Apr 23, 2016 9:23:06 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/works-servlet.xml]
Apr 23, 2016 9:23:10 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'works': initialization completed in 5153 ms
Apr 23, 2016 9:23:10 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Apr 23, 2016 9:23:10 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Apr 23, 2016 9:23:10 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 12093 ms
私はURL http://localhost:8080/KnockKnocks/welcome.html accressしようと、私はエラーHTTPステータス404を持っている - /KnockKnocks/welcome.htmlを。
誰かが私を助けてくれることを感謝します。
よろしく
RequestMappingの代わりにvalueを使用してテストします。 –
名前の代わりに値を追加しましたが、私は同じprobを持っています。編集 –
の質問を参照してください。なぜあなたのpom.xmlに "sourceDirectory"がありますか?私はそれが間違っていると言っているわけではありません。目的が何であるか、あなたの問題にそれが関係しているかどうかは不思議です。 –