简体   繁体   English

jsp文件中的springmvc maven链接文件

[英]springmvc maven link files in jsp file

I use eclipse, springmvc and maven. 我使用eclipse,springmvc和maven。 I created a folder under 我在下面创建了一个文件夹

Web-Content --> WEB-INF --> resources 网页内容-> WEB-INF->资源

I added the following into my servlet: 我将以下内容添加到我的servlet中:

 <mvc:resources mapping="/resources/**" location="/WEB-INF/resources/" />
<mvc:annotation-driven />

Then I try to include a picture into my index.jsp file.(Web-Content->index.jsp) 然后我尝试将图片包含到我的index.jsp文件中。(Web-Content-> index.jsp)

<img src = "/resources/images/Logo.png" />

But it's not loading my image. 但这不是加载我的图像。 I tryed many tutorials but it doesn't work. 我尝试了许多教程,但是没有用。 I guess I'm something basic wrong. 我想我是基本的错。 Can you tell me whats wrong? 你能告诉我怎么了吗?

EDIT: 编辑:

my serlvet got this 我的天鹅绒有这个

<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />

In my jsp file I did this: 在我的jsp文件中,我这样做:

<img src="<c:url value="/resources/logo.png" />"/>

I got resource folders with the logo.png file in the following places: 我在以下位置获得带有logo.png文件的资源文件夹:

main->resources
main->webapp->resources
main->webapp->WEB-INF->resources

It still doesn't work I also tried : 它仍然不起作用,我也尝试过:

<mvc:resources mapping="/resources/**"
               location="/, classpath:/WEB-INF/public-resources/"
               cache-period="10000" />

and include the picture with 并附上图片

/resources/images/logo.png

and the picture located in 和图片位于

src/main/webapp/images/logo.png

doesnt't work for me 对我不起作用

EDIT: 编辑:

I guess it this: 我猜是这样的:

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

got no effect to the program. 对程序没有影响。 I can always acces the url http://localhost:8080/test/resources/logo.png doenst matter if I got this mvc line in my serlvet or not. 无论我是否在Serlvet中获得此mvc行,我始终可以访问url http://localhost:8080/test/resources/logo.png If I change 如果我改变

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

to

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

I can't acces to the file with http://localhost:8080/test/resources1/logo.png but with http://localhost:8080/test/resources/logo.png 我无法使用http://localhost:8080/test/resources1/logo.png访问该文件,但无法访问http://localhost:8080/test/resources/logo.png

Greets Sam 向山姆致意

As an aside, while it is probably not best to make an Eclipse Dynamic Web Project and convert it to a Maven project through Eclipse, it will work, because Eclipse will put an entry into your POM that points to the WebContent directory. 顺便说一句,虽然最好不要制作一个Eclipse动态Web项目并将其通过Eclipse转换为Maven项目,但它会起作用,因为Eclipse会将指向WebContent目录的条目放入POM中。 Have a look you will probably find it there. 看看您可能会在那找到它。 There is nothing wrong with making a Dynamic Web Project per se, but I typically change the initial directory configuration to match maven's expectations in the Wizard and convert to a maven project right away. 制作Dynamic Web Project本身没有任何问题,但是我通常会更改初始目录配置,以符合向导中maven的期望,并立即转换为maven项目。 Much easy to work on the POM than copy jars to the lib directory. 与将jar复制到lib目录相比,在POM上进行工作要容易得多。

Otherwise, the resources directory you referring to should be in the root of your war file. 否则,您引用的resources目录应位于war文件的根目录中。 The best way to get it there is to put resources at the root of your WebContent directory, not under WEB-INF . 最好的获取方法是将resources放在WebContent目录的根目录中,而不是放在WEB-INF Try moving it there, open the .war file and inspect the contents to be sure it is in the root, and you should be good to go. 尝试将其移动到那里,打开.war文件并检查内容,以确保它位于根目录中,您应该一切顺利。

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

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