Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
spring mvc 3(3.2.5)和#x2B;tiles 3错误404未找到资源_Spring_Spring Mvc_Spring 3_Tiles2_Tiles 3 - Fatal编程技术网

spring mvc 3(3.2.5)和#x2B;tiles 3错误404未找到资源

spring mvc 3(3.2.5)和#x2B;tiles 3错误404未找到资源,spring,spring-mvc,spring-3,tiles2,tiles-3,Spring,Spring Mvc,Spring 3,Tiles2,Tiles 3,当我加载我的应用程序时,我只得到404资源未找到错误。。tomcat上根本没有日志 在这里您可以看到我的项目配置: 这是我的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

当我加载我的应用程序时,我只得到404资源未找到错误。。tomcat上根本没有日志

在这里您可以看到我的项目配置:

这是我的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>Spring Web MVC Application</display-name>

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

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/pages/*</url-pattern>
        <!--url-pattern>*.jsp</url-pattern-->
    </servlet-mapping>

    <urlrewrite default-match-type="wildcard">
    <rule>
        <from>/</from>
        <to>/pages/</to>
    </rule>
    <rule>
        <from>/**</from>
        <to>/pages/$1</to>
    </rule>
    <outbound-rule>
        <from>/pages/**</from>
        <to>/$1</to>
    </outbound-rule>
    </urlrewrite>

    <filter>
        <filter-name>urlRewriteFilter</filter-name>
        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    </filter>

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




    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/mvc-dispatcher-servlet.xml,
                     /WEB-INF/spring-security.xml,
                     /WEB-INF/spring-database.xml

        </param-value>

    </context-param>

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

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

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

</web-app>

SpringWebMVC应用程序
mvc调度器
org.springframework.web.servlet.DispatcherServlet
1.
mvc调度器
/页数/*
/
/页数/
/**
/页数/$1
/页数/**
/$1
URL重写过滤器
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
URL重写过滤器
/*
上下文配置位置
/WEB-INF/mvc-dispatcher-servlet.xml,
/WEB-INF/spring-security.xml,
/WEB-INF/spring-database.xml
org.springframework.web.context.ContextLoaderListener
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
/index.jsp
tiles.xml文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
        "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
        "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">

<tiles-definitions>
    <definition name="base.definition"
                template="/WEB-INF/pages/layout.jsp">
        <put-attribute name="title" value="" />
        <put-attribute name="header" value="/WEB-INF/pages/header.jsp" />
        <put-attribute name="menu" value="/WEB-INF/pages/menu.jsp" />
        <put-attribute name="body" value="" />
        <put-attribute name="footer" value="/WEB-INF/pages/footer.jsp" />
    </definition>

    <definition name="contact" extends="base.definition">
        <put-attribute name="title" value="Contact Manager" />
        <put-attribute name="body" value="/WEB-INF/pages/prueba2.jsp" />
    </definition>

</tiles-definitions>

mvc-dispatcher-servlet.xml

<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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <context:component-scan base-package="com.mkyong.common.controller" />

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>

        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

    <bean id="messageSource"
          class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <value>mymessages</value>
            </list>
        </property>
    </bean>


    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>
                org.springframework.web.servlet.view.tiles3.TilesView
            </value>
        </property>
    </bean>
    <bean id="tilesConfigurer"
          class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles.xml</value>
            </list>
        </property>
    </bean>


    <mvc:annotation-driven />

    <mvc:resources mapping="/resources/**" location="/resources/" />

    <context:annotation-config />

</beans>

/WEB-INF/pages/
.jsp
我的信息
org.springframework.web.servlet.view.tiles3.TilesView
/WEB-INF/tiles.xml
spring-security.xml

<beans:beans xmlns="http://www.springframework.org/schema/security"
             xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">

    <!--import resource="../database/spring-database.xml"/-->


    <http auto-config="true" access-denied-page="/accessDenied">

        <intercept-url pattern="/login*" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
        <intercept-url pattern="/*" access="ROLE_USER" />
        <form-login login-page="/login" default-target-url="/prueba2"
                    authentication-failure-url="/loginfailed.jsp"/>
        <logout logout-success-url="/logout" />
    </http>

    <authentication-manager>
        <authentication-provider>

            <jdbc-user-service data-source-ref="dataSource"

                               users-by-username-query="
                    select username,password, enabled
                    from users where USERNAME=?"

                               authorities-by-username-query="
                    select u.username, ur.authority from users u, user_roles ur
                    where u.user_id = ur.user_id and u.username =?  "

                    />
        </authentication-provider>
    </authentication-manager>


</beans:beans>

这是我的控制器:

@Controller
@RequestMapping("/prueba2")
public class controller2 extends AbstractController {

    Stock stock=new Stock();
    List stockList=new ArrayList<Stock>();
    ApplicationContext appContext = new ClassPathXmlApplicationContext("spring/config/BeanLocations.xml");
    StockBo stockBo = (StockBo)appContext.getBean("stockBo");


   /*@RequestMapping(method = RequestMethod.GET)
    public Stock returnCustomer(ModelMap model) {
        stock=stockBo.findByStockCode("7668");
        model.addAttribute("miStock", stock);
        return stock;


    }*/





    protected ModelAndView handleRequestInternal (HttpServletRequest req, HttpServletResponse res) throws Exception{
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String name = user.getUsername();
        Map<String, Object> model = new HashMap<String, Object>();
        stockList=stockBo.findAll();
        stock=stockBo.findByStockCode("7668");
        model.put("listaStock",stockList);
        model.put("miStock", stock);
        model.put("nombreUsuario", name);
        System.out.println("lista objetos--->" + stockList.toString());
        return new ModelAndView( "prueba2", "model", model );
    }

    public StockBo getStockBo() {
        return stockBo;
    }

    public void setStockBo(StockBo stockBo) {
        this.stockBo = stockBo;
    }
}
@控制器
@请求映射(“/prueb2”)
公共类控制器2扩展了AbstractController{
股票=新股票();
List stockList=new ArrayList();
ApplicationContext appContext=new ClassPathXmlApplicationContext(“spring/config/BeanLocations.xml”);
StockBo StockBo=(StockBo)appContext.getBean(“StockBo”);
/*@RequestMapping(method=RequestMethod.GET)
公众股票返回客户(模型地图模型){
stock=stockBo.findByStockCode(“7668”);
model.addAttribute(“误锁”,库存);
退货;
}*/
受保护的ModelAndView HandlerRequestInternal(HttpServletRequest-req,HttpServletResponse-res)引发异常{
User User=(User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
字符串名称=user.getUsername();
映射模型=新的HashMap();
stockList=stockBo.findAll();
stock=stockBo.findByStockCode(“7668”);
模型出售(“listaStock”,股票列表);
模型。投入(“误投”,库存);
型号。put(“nombreUsuario”,名称);
System.out.println(“lista objetos-->”+stockList.toString());
返回新模型和视图(“prueba2”,“模型”,模型);
}
公共股票{
返回stockBo;
}
公共证券交易所(StockBo StockBo){
this.stockBo=stockBo;
}
}

我不知道你的问题的直接答案,但以下是我的方法:

首先,如果我正确理解了您的问题,那么您会希望转到url
http://localhost:8080/SpringExample
会将您重定向到登录页面,但这不会发生(您看到的是404)。我假设您已经检查了您的应用程序是否实际部署到SpringExample上下文中

有几件事可能会影响URL的解释和重定向方式。首先是Spring,它将以/pages/开头的任何请求映射到Spring dispatcher。接下来,您有一些URL重写,因为它是在过滤器中完成的,所以应该在SpringDispatcherServlet之前进行。您还拥有一个侦听器,用于加载所有spring上下文配置。第三,您有Spring安全性,它在过滤器中实现。最后,您得到了tiles配置,理论上,如果找不到资源,也可能导致404错误,尽管看起来您的配置还可以

这是相当复杂的,如果事情没有按照正确的顺序发生,你就会有问题。我要做的是去掉每个组件,然后开始逐个添加它们。首先,除去欢迎文件配置之外的所有内容,看看是否可以通过转到url访问/index.jsp。然后加入SpringBack,看看是否仍然可以使用它。然后是加载项URL重定向,然后是安全性,然后是平铺。这将帮助您缩小问题的范围。


 <bean id="viewResolver" class="org.springframework.web.servlet.view.tiles3.TilesViewResolver"/>
 <bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/tiles.xml</value>
        </list>
    </property>
</bean>
/WEB-INF/tiles.xml

尝试编写代码=>

无需编写此代码即可 /WEB-INF/pages/

    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

.jsp

您能否发布您试图发布的请求以及相应的控制器方法。我添加了我的控制器。。我的想法是,当我转到localhost:8080/SpringExample时,它应该将我重定向到登录页面,然后在我放置我的用户并传递到“prueb2.jsp”之后,再转到“prueb2.jsp”。是的。。应用程序被部署到SpringExample上下文中。。事实上,我的应用程序的欢迎页面是“index.jsp”,它重定向到“prueba2.jsp”,但spring security确保在转到“prueba2.jsp”之前重定向到登录页面。。所有这些都发生在我加载我的应用程序时,在我看到的url“”中,但它说它找不到资源((是的,我的登录页面存在,并且在spring security中指向它的路径还可以)我想我必须尝试你所说的……逐个删除。