1

I want to ask why my external css/js was not load in my jsp. My struts.xml content :

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
 "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
  "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<constant name="struts.action.extension" value=""/> 

<package name="default" namespace="/" extends="struts-default">

    <default-action-ref name="home" />

    <action name="home">
        <result name="success">index.jsp</result>
    </action>

</package>  

</struts>

My web.xml content :

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_2_5.xsd"
       version="2.5">

<display-name>Test</display-name>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> 

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<error-page>
    <error-code>404</error-code>
    <location>error404.jsp</location>
</error-page>

</web-app>

I load my css in my jsp using this code

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

I also try use this code

<link rel="stylesheet" type="text/css" href="<s:url value="/style/css/style.css"/>"/>

even, it's get error when I want to display an image on my jsp

<img src="<s:url value="/style/images/icon/car.png"/>" />

What wrong with this, whether cause of this code (web.xml)

<filter-mapping>
   <filter-name>struts2</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>

Thank you for your response.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Mahadi Siregar
  • 615
  • 3
  • 17
  • 38
  • what if you use absolute path..? like your web-app/style/css/style.css" – Umesh Awasthi Aug 13 '12 at 06:07
  • @BheshGurung, the error that css was not loaded and when i open view page source then i click css link, it return a blank page – Mahadi Siregar Aug 14 '12 at 08:59
  • @UmeshAwasthi, this project i build using maven, so there is no web-app folder – Mahadi Siregar Aug 14 '12 at 09:00
  • possible duplicate of [Struts2 .action extension causing CSS, JavaScript and Struts Dojo to break](http://stackoverflow.com/questions/12607075/struts2-action-extension-causing-css-javascript-and-struts-dojo-to-break) – Aleksandr M Jan 15 '15 at 11:00

4 Answers4

2

turned out just because this code in my struts.xml

<constant name="struts.action.extension" value=""/> 

when i remove it, everything work fine. Sorry n thank u

Mahadi Siregar
  • 615
  • 3
  • 17
  • 38
0

For sure this is a path problem. You can use Firebug with Network to see which exact URL the browser is trying to load. After that, you will be able to correct the css URL. For sure you can't use insite a tag.

Alexandre Lavoie
  • 8,711
  • 3
  • 31
  • 72
  • "NetworkError: 404 Not Found - http://localhost:8080/vhmon/style/css/style.css" but when i change struts url pattern from /* to be /main (for example), the css is loaded – Mahadi Siregar Aug 14 '12 at 09:27
0

Your Filters are blocking those images,CSS

Chandra Shekhar
  • 262
  • 2
  • 4
0

Your external folder is not in the root of the webserver; so it dosen't recognize it, then you have to add it

Bourkadi
  • 738
  • 1
  • 7
  • 17