简体   繁体   中英

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

Hi I'm putting together a fairly basic app using spring 4 MVC. I am using config java classes rather than 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.

So I have included the include-prelude into my web.xml file

<?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. However it is not working for the JSP's accessed via spring MVC. It is working in a similar application I inherited which has the spring bootstrap config in xml files rather than java classes. I won't have millions of pages so I guess I can use a jsp:include but...

Can anyone tell me how I should go about getting the header.jspf picked up ? Ideally I'd like to keep the config in java classes but perhaps I have to use the 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. 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!). Do you think I should be using somethign other than JSPs & jspf's

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):

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

So your web.xml should look like this at the beginning:

<?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 . If you use *.jsp in url mapping and use jsp as view it will give you 404 everytime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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