views:

244

answers:

2

Hi, I am stuck on this Spring MVC tutorial for newbies: http://sites.google.com/site/springmvcnetbeans/step-by-step/

I am the point 1.12 "Try out application". When I put in my address bar hello.htm it doesn't work, but hello.jsp works. But I guess point was somehow to hide this JSP extension.

I followed tutorial precisely. What might I have done wrong?

skaffman suggested posting web.xml and servlet mapping xml file, so here they are. I added only what tutorial said (but with another package name, rest is generated by NetBeans)

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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"&gt;
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>springsample</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springsample</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>redirect.jsp</welcome-file>
    </welcome-file-list>
</web-app>

springsample-servlet.xml

<?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:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"&gt;

    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>

    <!--
    Most controllers will use the ControllerClassNameHandlerMapping above, but
    for the index controller we are using ParameterizableViewController, so we must
    define an explicit mapping for it.
    -->
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="index.htm">indexController</prop>
            </props>
        </property>
    </bean>

    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp" />

    <!--
    The index controller.
    -->
    <bean name="indexController"
          class="org.springframework.web.servlet.mvc.ParameterizableViewController"
          p:viewName="index" />

    <bean name="/hello.htm"
            class="controllers.HelloController" />

</beans>
A: 

I can see several differences. The file in the tutorial is called springapp-servlet.xml, not springsample-servlet.xml (see step 1.8), and it only contains one bean, the hello.htm bean. There is no mention of springsample-servlet.xml anywhere in the whole thing.

skaffman
Well I renamed it to SpringSample
AspNewbie
But I am using Java EE 6 , guy uses Java EE 5. Now I renamed it properly and replaced files with exactly those from tutorial ... well it won't compile, failing here : <nbdeploy clientUrlPart="${client.urlPart}" debugmode="false" forceRedeploy="${forceRedeploy}"/>
AspNewbie
and also I use GlassFish 3 not GlassFish 2 UR1
AspNewbie
@AspNewbie: So when you said "I followed tutorial precisely", you meant except the bits where you decided not to? I suggest you start again, and follow the instructions. When it's working, *then* start modifying it.
skaffman
A: 

The tutorial tells you to place the file in the webapp root web/hello.jsp but you've told spring to look for it in /WEB-INF/jsp/hello.jsp Did you move the file into that folder? The fact that you can find it at /springsample/hello.jsp would indicate you did not.

Affe
the guy who's written the tutorial hadn't either :O
AspNewbie
his springapp-servlet.xml in section 1.6 doesn't have an overridden viewResolver like yours does.
Affe
ahhok I am going to do complete clone of his app :(
AspNewbie