简体   繁体   English

使用Spring 4不会从web.xml中选择include-prelude

[英]include-prelude not being picked from web.xml using Spring 4

Hi I'm putting together a fairly basic app using spring 4 MVC. 嗨,我正在使用Spring 4 MVC编写一个相当基本的应用程序。 I am using config java classes rather than xml config. 我正在使用config java类而不是xml config。 I'm pretty new to this but all is slowly moving forward well. 我对此很陌生,但是一切都进展顺利。 I have hit a problem though in that I wanted to include a header into all the jsp page views. 我遇到了一个问题,尽管我想在所有jsp页面视图中包含标题。

So I have included the include-prelude into my web.xml file 所以我已经将include-prelude包含在我的web.xml文件中

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
     version="3.1">

<display-name>Web Application</display-name>
<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <include-prelude>/WEB-INF/views/include/header.jspf</include-prelude>        </jsp-property-group>
</jsp-config>
</web-app>

This is working if I add a dummy jsp file into the webapp folder (I'm using maven and eclipse) and access it directly. 如果我将一个虚拟的jsp文件添加到webapp文件夹(我正在使用maven和eclipse)并直接访问它,则此方法有效。 However it is not working for the JSP's accessed via spring MVC. 但是,它不适用于通过Spring MVC访问的JSP。 It is working in a similar application I inherited which has the spring bootstrap config in xml files rather than java classes. 它在我继承的类似应用程序中运行,该应用程序在xml文件而非Java类中具有spring bootstrap config。 I won't have millions of pages so I guess I can use a jsp:include but... 我不会有数百万的页面,所以我想我可以使用jsp:include但...

Can anyone tell me how I should go about getting the header.jspf picked up ? 谁能告诉我我应该如何获取header.jspf? Ideally I'd like to keep the config in java classes but perhaps I have to use the xml bootstrapping ? 理想情况下,我想将配置保留在Java类中,但也许我必须使用xml bootstrapping?

Also as a supplementary question which is not really what I'm asking so please ignore if it's against all the rules (!) when I've googled this a bit I keep reading that JSP's are no longer the way to go for views. 另外,作为补充性问题,它并不是我真正要问的问题,因此,当我在Google上进行了一些搜索时,请忽略它是否违反所有规则(!),我一直在阅读,JSP不再是寻求意见的方式。 I'm writing a fairly basic intranet forms app (I've recently switched from microsoft technologies so apologies if you don't like that terminology!). 我正在写一个相当基本的Intranet表单应用程序(我最近从Microsoft技术切换到了抱歉,如果您不喜欢该术语的话!)。 Do you think I should be using somethign other than JSPs & jspf's 您是否认为我应该使用JSP和jspf以外的工具

Thanks 谢谢

In case you are wondering what is the answer to the OP'S question, the answer is to simply add this to your web.xml tag (if you are using Tomcat instead of GlassFish): 如果您想知道OP的问题的答案是什么,答案是将其简单地添加到web.xml tag (如果您使用的是Tomcat而不是GlassFish):

xmlns:my="http://jakarta.apache.org/tomcat/jsp2-example-taglib"

So your web.xml should look like this at the beginning: 因此,您的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"
        xmlns:my="http://jakarta.apache.org/tomcat/jsp2-example-taglib">

I hope this could helped you ;) 我希望这可以帮助您;)

You can use jsp.There is no problem with that the only thing you need to change is instead of giving url-mapping like .jsp use url mapping .abc, here you can use abc,xyz,ani,spring,do etc anything rather then jsp.So it will work fine . 您可以使用jsp。没有问题,您唯一需要更改的就是不用像.jsp那样使用url映射 .abc来进行url映射 ,这里您可以使用abc,xyz,ani,spring,do等然后是jsp.So可以正常工作。 If you use *.jsp in url mapping and use jsp as view it will give you 404 everytime. 如果您在网址映射中使用* .jsp并将jsp作为视图,则每次都会显示404。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM