InternalResourceViewResolver和Winstone的问题

时间:2011-04-14 19:55:39

标签: java spring jsp java-ee

我的春季项目有问题。

这是我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <servlet>
        <servlet-name>greenmine</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>greenmine</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>
            index.jsp
        </welcome-file>
    </welcome-file-list>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/greenmine-servlet.xml
        </param-value>
    </context-param>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
</web-app>

和我的greenmine-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:context="http://www.springframework.org/schema/context"
    xmlns:security="http://www.springframework.org/schema/security"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/security
       http://www.springframework.org/schema/security/spring-security-3.0.3.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <context:component-scan base-package="at.tripwire.greenmine.controller" />
    <context:component-scan base-package="at.tripwire.greenmine.domain.dao" />
    <context:component-scan base-package="at.tripwire.greenmine.service" />
    <context:component-scan base-package="at.tripwire.greenmine.module" />

    <mvc:annotation-driven />
    <mvc:resources location="/css/" mapping="/css/**" />
    <mvc:resources location="/images/" mapping="/images/**" />
    <mvc:resources location="/js/" mapping="/js/**" />

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <!-- Hibernate Configuration -->
    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName">
            <value>com.mysql.jdbc.Driver</value>
        </property>
        <property name="url">
            <value>jdbc:mysql://localhost/greenmine</value>
        </property>
        <property name="username">
            <value>root</value>
        </property>
        <property name="password">
            <value>root</value>
        </property>
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="annotatedClasses">
            <list>
                <value>at.tripwire.greenmine.domain.Project</value>
                <value>at.tripwire.greenmine.domain.Profile</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
    </bean>

    <!-- Spring Security -->
    <security:http auto-config="true" use-expressions="true">
        <security:intercept-url pattern="/login"
            access="permitAll" />
        <security:intercept-url pattern="/j_spring_security_check"
            access="permitAll" />
        <security:intercept-url pattern="/css/**"
            filters="none" />
        <security:intercept-url pattern="/js/**"
            filters="none" />
        <security:intercept-url pattern="/images/**"
            filters="none" />
        <security:intercept-url pattern="/**"
            access="isAuthenticated()" />
        <security:form-login login-page="/login"
            login-processing-url="/j_spring_security_check" default-target-url="/projects"
            authentication-failure-url="/login?error=1" />
        <security:logout logout-success-url="/login"
            logout-url="/logout" />
    </security:http>

    <security:authentication-manager>
        <security:authentication-provider
            user-service-ref="profileUserDetailsService">
            <security:password-encoder hash="md5" />
        </security:authentication-provider>
    </security:authentication-manager>
</beans>

next:我的LoginController.java

@Controller
public class LoginController {

    @RequestMapping("/login")
    public ModelAndView handleLoginForm(HttpServletRequest request) {
        String errParam = request.getParameter("error");
        ModelAndView mv = new ModelAndView("login/login");
        if(errParam != null) {
            mv.addObject("error", "Benutzer oder Kennwort unzul&auml;ssig");
        }
        return mv;
    }
}

我正在使用Winstone Servlet Engine v0.9.10。 当我转到http://localhost:8080/login时,它会出现以下错误:

14.04.2011 21:48:13 org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNUNG: No mapping found for HTTP request with URI [/WEB-INF/jsp/login/login.jsp] in DispatcherServlet with name 'greenmine'

但是login.jsp位于WEB-INF / jsp / login / login.jsp

中 希望有人能帮助我。我已经找了两个星期。

2 个答案:

答案 0 :(得分:2)

以下标签解决了我的问题:

<mvc:default-servlet-handler/>

答案 1 :(得分:0)

你只需要在配置中添加一个处理程序..

查看您的代码,您可以添加以下行来解决问题

<bean class=" org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

我们说注释将由DefaultAnnotationHandler类处理,当您根据注释定义控制器时,此类知道该怎么做 并且AnnotationMethodHandlerAdapter理解方法的注释(例如@RequestMapping)。