0

在我添加一个扩展 AbstractController 的控制器之前,我的项目运行良好,然后当我尝试打开“/”根页面时,我总是得到著名的 404 页面。我在我的项目中集成了 spring-security,所以当我打开“/”页面时,我必须自动看到登录表单,或者如果我已经登录,则查看索引。

这是我的调度程序 servlet:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">



    <context:component-scan base-package="gestion.delegation.controller" />
    <mvc:annotation-driven />

 <bean class="org.springframework.web.servlet.view.XmlViewResolver">
       <property name="location">
           <value>/WEB-INF/spring-pdf-views.xml</value>
       </property>
       <property name="order" value="0" />
    </bean>

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



</beans>    

这是控制器:

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class RevenueReportController extends AbstractController{

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
        HttpServletResponse response) throws Exception {

        String output =
            ServletRequestUtils.getStringParameter(request, "output");



        if(output ==null || "".equals(output)){
            //return normal view
            return new ModelAndView("RevenueSummary");

        }else if("PDF".equals(output.toUpperCase())){
            //return excel view
            return new ModelAndView("PdfRevenueSummary");

        }else{
            //return normal view
            return new ModelAndView("RevenueSummary");

        }   
    }   
}

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>GestionPersonnel</display-name>
  <!-- Spring MVC -->

    <servlet>
        <servlet-name>Dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>default</servlet-name>

        <servlet-class>
            org.apache.catalina.servlets.DefaultServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>

    </servlet>

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.css</url-pattern>
    <url-pattern>*.png</url-pattern>
     <url-pattern>*.gif</url-pattern>
    <url-pattern>*.js</url-pattern>
     <url-pattern>*.htm</url-pattern>
</servlet-mapping>

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

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/Dispatcher-servlet.xml,
            /WEB-INF/spring-datasource.xml,
            /WEB-INF/spring-security.xml,
            /WEB-INF/spring-service.xml
        </param-value>
    </context-param>

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



</web-app>

我也永远无法得到这个abstactController映射的页面。请问我的调度员文件正确吗??我想做与这个问题中所说的相同的事情:生成 pdf ......但我不知道错误在哪里。请帮助......

4

1 回答 1

0

Don't extend AbstractController, just annotate using org.springframework.stereotype.controller

eg :

@Controller
@RequestMapping(value = "/")
public class RevenueReportController
于 2013-06-12T13:55:15.720 回答