[英]How is ContextLoaderListener from Spring being run even when web.xml does not include it?
[英]include-prelude not being picked from web.xml using Spring 4
嗨,我正在使用Spring 4 MVC編寫一個相當基本的應用程序。 我正在使用config java類而不是xml config。 我對此很陌生,但是一切都進展順利。 我遇到了一個問題,盡管我想在所有jsp頁面視圖中包含標題。
所以我已經將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>
如果我將一個虛擬的jsp文件添加到webapp文件夾(我正在使用maven和eclipse)並直接訪問它,則此方法有效。 但是,它不適用於通過Spring MVC訪問的JSP。 它在我繼承的類似應用程序中運行,該應用程序在xml文件而非Java類中具有spring bootstrap config。 我不會有數百萬的頁面,所以我想我可以使用jsp:include但...
誰能告訴我我應該如何獲取header.jspf? 理想情況下,我想將配置保留在Java類中,但也許我必須使用xml bootstrapping?
另外,作為補充性問題,它並不是我真正要問的問題,因此,當我在Google上進行了一些搜索時,請忽略它是否違反所有規則(!),我一直在閱讀,JSP不再是尋求意見的方式。 我正在寫一個相當基本的Intranet表單應用程序(我最近從Microsoft技術切換到了抱歉,如果您不喜歡該術語的話!)。 您是否認為我應該使用JSP和jspf以外的工具
謝謝
如果您想知道OP的問題的答案是什么,答案是將其簡單地添加到web.xml tag
(如果您使用的是Tomcat而不是GlassFish):
xmlns:my="http://jakarta.apache.org/tomcat/jsp2-example-taglib"
因此,您的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">
我希望這可以幫助您;)
您可以使用jsp。沒有問題,您唯一需要更改的就是不用像.jsp那樣使用url映射 .abc來進行url映射 ,這里您可以使用abc,xyz,ani,spring,do等然后是jsp.So可以正常工作。 如果您在網址映射中使用* .jsp並將jsp作為視圖,則每次都會顯示404。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.