Hi All,

I have one strange issue, JSP cannot Identify the JS, CSS file path when URL pattern is /*. Let me explain in detail.

Irrespective of relative path my application should have to call Home.jsp. So for that I have specified URL pattern as /*. This logic is working fine.
The application is calling JSP page but It cannot call the JS file. In the below Sample code I try to print two alert massages. But I am able to see only one alert message "welcome". Not able to see the alert message in Hi.js file. I tried with all possible scenarios by changing path but its not working. CAN ANY BODY PLEASE HELP ME IN THIS.

One more thing I have to mention here when I change the URL pattern to some /xyz its working fine. Please Help me in this issue.

My Directory Structure.

RedirectApp
+-----WEB-INF
+-----Home.jsp
+-----Hi.js
Web.xml

<servlet>
    <description></description>
    <display-name>Hello</display-name>
    <servlet-name>Hello</servlet-name>
    <jsp-file>/Home.jsp</jsp-file>    
  </servlet>
  <servlet-mapping>
    <servlet-name>Hello</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>

Home.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script language="javascript" type="text/javascript" src="Hi.js"></script>
<meta http-equiv="Content-Type" content="text/javascript; charset=ISO-8859-1">
</head>
<body>
<script>
window.onload = function(){
		welcome();
		 HI();
	}
function welcome() {
	alert("welcome");
}
</script>

</body>
</html>

Hi.js

function HI() {
	alert("Calling Out side JS File");
}

you can try

<script language="javascript" 
        type="text/javascript" 
        src="<%=request.getContextPath()%>/Hi.js">
</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.