在调度程序servlet中映射资源(Resin Server)

时间:2015-04-08 06:23:49

标签: java maven spring-mvc resin

这是我的dispacter-servlet.xml文件。当我在resin pro 4.0.36上部署项目时,它会加载我的索引页面和内容但是FAILS加载存储在staticresources文件夹下的css文件和图像

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

<context:component-scan base-package="com.dogears" />


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

<import resource="classpath:beans.xml"/>

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

请任何人都可以告诉我如何mapp我的静态资源文件夹,这样每当请求是patter / resources / *时,它会将请求重定向到静态资源文件夹。 staticresources文件夹位于 MyspringProject / src / main / webapps目录

3 个答案:

答案 0 :(得分:0)

我认为您需要将staticresources目录映射为根目录。在Eclipse中,它将是一个&#34; Source Folder&#34;在IntelliJ a&#34;资源根&#34;。

根据您的IDE,请参阅以下帮助文档:

Eclipse:http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-wizard-source-folder.htm

IntelliJ:https://www.jetbrains.com/webstorm/help/configuring-folders-within-a-content-root.html

答案 1 :(得分:0)

假设您的项目目录结构类似于

- src
    - main
      - webapp
        - resources
          - css
            - abc.css
          - images
            - xyz.jpg

&安培;您的.html.jsp页面位于以下目录中

- webapp
  - index.jsp
  - pages
    - welcome.jsp

然后您可以在 index.jsp 页面 BaseURL/index.jsp

>添加资源链接 >
<link href="resources/css/abc.css" rel="stylesheet" type="text/css" />  

<body>
    <img src="resources/images/xyz.jpg" alt="" style="width:100px;height:100px" />
</body>

&安培; welcome.jsp ,网址为 BaseURL/pages/welcome.jsp

<link href="../resources/css/abc.css" rel="stylesheet" type="text/css" /> 

<body>
    <img src="../resources/images/xyz.jpg" alt="" style="width:100px;height:100px" />
</body>

希望这会对你有所帮助。

答案 2 :(得分:0)

我终于找到了解决方案。我已经将我的spring webapp部署在树脂目录的webapps文件夹中。

当您在树脂服务器上部署spring应用程序而不是 tomcat 时,我意识到<mvc:resource />映射标记有效

因此我通过首先创建我的项目的war文件然后在桌面上提取war文件然后将war文件中的所有内容放在 webapps / root 中来解决这个问题(而不是webapps文件夹)树脂目录的文件夹。然后从我的索引页面我使用JSTL TAG包含外部样式表。

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>

<link rel="stylesheet" type="text/css" href="<c:url  value="/staticresources/externalcss.css"/>">

</head>
<body>
<h2 class="text_style">Hello World!</h2>
</body>
</html>

IT工作!!!

相关问题