Reputation: 11435
I have a struts 2 application. Version 2.2.3. My problem is that the application is not able to load the javascript files. I have a jsp file that has the following at the top
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Ajax</title>
<script type="text/javascript" src=" <s:url value="/static/script/jquery/jquery-1.6.min.js" includeParams="false"/>" ></script>
<script type="text/javascript" src=" <s:url value="/static/script/jquery/jquery-ui-1.8.12.custom.min.js" includeParams="false"/>" ></script>
</head>
my files are located in the following dir
struts2tutorial/static/script/jquery
In firebug i see the following url
<script src=" /struts2tutorial/static/script/jquery/jquery-1.6.min.js" type="text/javascript">
If i do the following on browser. I get a 404 file not found. Not sure what is that I am doing wrong
http://localhost:8010/struts2tutorial/static/script/jquery/jquery-1.6.min.js
Upvotes: 1
Views: 5641
Reputation: 3342
For me the problem was in my web.xml. you have to add " /struts/* " to your filter pattern because the js files aren't really files. I assume this is a struts action behind the url even if it's not detected by the struts2-config-brower plugin.
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
<url-pattern>/struts/*</url-pattern>
</filter-mapping>
Upvotes: 0
Reputation: 11055
Unless you have specially configured your action extension to match everything, you shouldn't need the /static or the <s:url/>
stuff at all. Assuming that the script directory is in your WAR file/exploded directory, this is sufficient:
<script type="text/javascript" src="${pageContext.request.contextPath}/script/jquery/jquery-1.6.min.js"></script>
Upvotes: 2
Reputation: 360
try
http://localhost:8010/static/script/jquery/jquery-1.6.min.js
in address bar and the code below in your jsp
<script type="text/javascript" src=" <s:url value="static/script/jquery/jquery-1.6.min.js" includeParams="false"/>" ></script>
Upvotes: 0
Reputation: 8686
Putting the javascript files in struts2tutorial/static/script/jquery doesn't necessarily mean that's the path that's used when you deploy the application to your server. Check to see where that path ends up getting mapped to on your server.
Upvotes: 0