Javascript not working on jsp pages redirected from servlet

I have a servlet that does forward using requestdispatcher () to one of my jsp pages

request.getRequestDispatcher("/WEB-INF/view/mypage.jsp").forward(
                    request, response);

The target mypage.jsp has some jquery goodwill that is required to create some show / hide files, but for some reason jquery does not start when jsp is displayed after redirecting from the servlet, but it works when I directly access the page through the address bar (I immediately moved the page outside of web-inf for access).

Even simple <body onload="alert('Testing')">also does not work. I also use HTML5 and jquerymobile in my jsp.

Any answers to filling the gaps in my knowledge would be wonderful. Thanks

The following is the jsp page:

<!DOCTYPE html>
<html>
<head>
<title>My App</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
</head>
<body onload="alert('Even this is not popping up')">
-- Stuff--
</body>
</html>
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
</head>
<body onload="alert('Even this is not popping up')">
-- Stuff--
</body>
</html>
+3
5

, mypage.jsp. /WEB -INF, . , , /WEB -INF.

/WEB -INF, , , , , JSP - - , /WEB/INF. .

+1

, , . . , - JavaScript , jquery.js .

0

RequestDispatcher is a redirection that works similar to how the application works, so your pages may be served, but static files will not be available because they are requested by the front end.

Move js files from WEB-INF, css and images.

0
source

Use it as

window.alert("This is alert");

window.document.location.href="mypage.html";

When a warning message appears, when you click ok, you will be redirected to the desired page.

0
source

All Articles