GET http://localhost:8080/static/My/ net::ERR_ABORTED 404 (Not Found)
出现此问题主要是引入的js、css不起作用。
路径引入
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:///TR/html4/">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<script type="text/javascript" src="../static/My/" charset="utf-8"></script>
</head>
不起作用
(1)改为:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:///TR/html4/">
<%
String path = ();
String basePath = ()+"://"+()+":"+()+path+"/";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<script type="text/javascript" src="<%=basePath%>/static/My/" charset="utf-8"></script>
</head>
问题解决
(2)还有就是strut2拦截了静态资源的加载,修改struts2的文件,添加:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"/dtds/struts-2.">
<struts>
<package name="hello" extends="struts-default" >
</package>
<constant name="" value="/static/.*?"></constant>
</struts>