簡體   English   中英

使用注釋幫助第一個Spring MVC頁面

[英]Help with first spring MVC page using annotations

我正在嘗試獲取http:// localhost:8080 / test映射到index.jsp頁面。

jsp文件存儲在以下文件夾中:

/web-inf/jsp/index.jsp

我到目前為止所擁有的:

@Controller
public class HomeController {


    @RequestMapping(value = "/test")
    public String Test(){

        return "index";
    }



}

我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">

        <!-- Handles all requests into the application -->
    <servlet>
        <servlet-name>springmvc1</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Maps all /app requests to the DispatcherServlet for handling -->
    <servlet-mapping>
        <servlet-name>springmvc1</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

還有我的springmvc1-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!--
    - DispatcherServlet application context for PetClinic's web tier.
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
        xmlns:oxm="http://www.springframework.org/schema/oxm"
        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/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">



    <context:component-scan base-package="com.example.web"/>



    <!--
        - The BeanNameViewResolver is used to pick up the visits view name (below).
        - It has the order property set to 2, which means that this will
        - be the first view resolver to be used after the delegating content
        - negotiating view resolver.
     -->
    <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="1"/>
    <!--

        - This bean configures the 'prefix' and 'suffix' properties of
        - InternalResourceViewResolver, which resolves logical view names
        - returned by Controllers. For example, a logical view name of "vets"
        - will be mapped to "/WEB-INF/jsp/vets.jsp".
    -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/"
            p:suffix=".jsp" p:order="2"/>



</beans>

我收到錯誤消息:

HTTP Status 404 - Servlet springmvc1 is not available

type Status report

message Servlet springmvc1 is not available

description The requested resource (Servlet springmvc1 is not available) is not available.

可能是什么問題呢?

Apache Tomcat/6.0.24

這是服務器提供的輸出:

Feb 9, 2010 11:14:03 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_17\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;E:\Program Files\CodeSmith\v4.1\;C:\WINDOWS\system32\WindowsPowerShell\v1.0;E:\Program Files\QuickTime\QTSystem\;E:\Program Files\TortoiseSVN\bin;C:\Documents and Settings\Administrator\My Documents\Downloads\nant-0.85-rc4-bin\nant-0.85-rc4;C:\Program Files\CodeSmith\v5.1\;%JAVA_HOME%\bin;%M2%;e:\program files\jetbrains\intellij idea 9.0.1\jre\jre\bin
Feb 9, 2010 11:14:03 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Feb 9, 2010 11:14:03 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 377 ms
Feb 9, 2010 11:14:03 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Feb 9, 2010 11:14:03 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.24
Feb 9, 2010 11:14:03 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor ROOT.xml
Feb 9, 2010 11:14:03 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory docs
Feb 9, 2010 11:14:03 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
Feb 9, 2010 11:14:03 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory host-manager
Feb 9, 2010 11:14:04 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory manager
Feb 9, 2010 11:14:04 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Feb 9, 2010 11:14:04 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Feb 9, 2010 11:14:04 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/31  config=null
Feb 9, 2010 11:14:04 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 623 ms
Connected to server

更新tomcat日志

似乎tomcat日志文件沒有立即更新,我猜它幾分鍾就被丟棄了?

問題如下:

Feb 9, 2010 11:14:03 AM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet  threw load() exception
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1484)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1329)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1095)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4187)

字符串是,我在IntelliJ的“外部庫”文件夾中有spring 3.0 rc3 另外,如果我輸入org.springframework.web.servlet.DispatcherServlet intellisense會執行自動完成,我認為這意味着庫已作為項目的一部分被拾取。

Servlet springmvc1 is not available

歸結為

HttpServlet springmvc1 = new DispatcherServlet(); 

服務器啟動期間失敗。

閱讀服務器啟動日志以獲取與此相關的任何信息/警告/錯誤/詳細信息。 我對ClassNotFoundExceptionNoClassDefFoundError ,反過來指示在運行時類路徑中缺少JAR。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM