views:

461

answers:

1

I'm trying to get http://localhost:8080/test to map to the index.jsp page.

The jsp file is stored in the folder:

/web-inf/jsp/index.jsp

what I have so far:

@Controller
public class HomeController {


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

        return "index";
    }



}

My 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"&gt;

        <!-- 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>

And my 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"&gt;



    <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>

I am getting the error:

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.

What could be the problem?

Apache Tomcat/6.0.24

Here is the output that the server is giving:

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

Update tomcat log

It seems the tomcat log file is not updated immediatly, I guess it gets dumped very few minutes?

Below is the problem:

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)

The string thing is, I have spring 3.0 rc3 in my 'external libraries' folder in IntelliJ. Also, if I go and type org.springframework.web.servlet.DispatcherServlet intellisense does the auto-completion which I assume means the library is being picked up as being part of the project.

+2  A: 
Servlet springmvc1 is not available

This boils down to that

HttpServlet springmvc1 = new DispatcherServlet(); 

has failed during server's startup.

Read the server startup logs for any info/warnings/errors/details related to this. My cents on ClassNotFoundExceptions or NoClassDefFoundErrors which in turn indicate missing JAR's in the runtime classpath.

BalusC
Yes I tried looking. I am using IntelliJ IDEA, and the 'tomcat log' tab is empty,and also /tomcat/logs is also empty. I must be looking in the wrong place?
Blankman
What about the intellij console tab, does it says context test failed to initialize?
Teja Kantamneni
@Teja the window says 'output' on the top, not sure it is console or not. See the updated question above for the output.
Blankman
I see. Are you sure that you edited the correct `web.xml`? Are you also sure that you built/deployed the correct project? Are you sure that you accessed the correct host/port/context?
BalusC
I am using IntelliJ, so not sure how can I edit the wrong file, its a project so all the files are in the project folder right? The automatically fires up the browser and url for me.
Blankman
Try to just deploy project on server, run it and use a normal (external) webbrowser to access it. Another thing, you said you was using `http://localhost/test`, but the startup logs said that the server is listening on port 8080, not 80. You'll need to specify the port yourself as in `http://localhost:8080/test`.
BalusC
Sorry I meant to write http://localhost:8080/test (I am getting the error message from tomcat so it was the right port anyhow) hmm, this is frustrating! thanks for your help so far!
Blankman
ok turns out to be an error, I guess the tomcat logs are not dumped to file immediately? (updating question)
Blankman
You got a `ClassNotFoundException` exactly as I expected. The Struts JAR file(s) is missing in the runtime classpath. Download it from Struts homepage and drop in `/WEB-INF/lib`. That's all.
BalusC
But I'm using Spring and Spring MVC, I have the .jar's in my lib folder, and intellisense is picking up the org.springframework.web.servlet.DispatcherServlet so I am assuming it is there, I'll keep digging thanks man!
Blankman
in the module settings of intellij, go to web facet of the application -> on the right you will see modules and lib's to package make sure you have all your libraries selected to deploy
Teja Kantamneni
Sorry, I of course meant to say "Spring" instead of "Struts". But the same story still applies: it's missing in runtime classpath.
BalusC
@Teja I want to Project Structure | Facets | Web -> web (springmvc1) and to the right I see a panel for Deployment Descriptor that is using my web.xml, and below that is Web Resources directory and below that is 'source roots' which is checked. Is this the correct place?
Blankman
ok the project was referencing spring 3.0, but I downloaded and was using spring 3.0 rc3. that was the issue, thanks everyone! @Teja thanks you helped allot!
Blankman