I have following project structure
In exportPage.jsp JSP I have included JS files as
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<script type="text/javascript" src="<c:url value="/js/jquery-1.11.2.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/dataTables.tableTools.js"/>"></script>
But when I run app to access the page I am getting 404 error for both URLs. URL generated is as follow:
http://localhost:8090/springmvc/js/jquery-1.11.2.min.js
What I have to configure in STS to fixed this issue. Is this build path issue. By the way this is Maven type Spring Project in STS.
The problem is that:User does not have access to WEB-INF.So,your js files are in WEB-INF.When page load js files download to user PC and user has no access to this folder and you get error.You must create js folder outside WEB-INF.You can create your views in your WEB-INF because user has no access directly to this folder.
Related
If i build a war file and deploy it on tomcat, it cannot find the webjars which i have written in index.html as follows;
<script type="text/javascript" src="/webjars/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/webjars/angularjs/angular.min.js"></script>
so, had to manually change the src="{my_application_name}/webjars/jquery/jquery.min.js"
Is there a way i can do this dynamically?
When you point any path preceding with / using src tag, it will take absolute path and your request will be redirected to localhost:[port]/whatever_path_is.
So I suggest you to use relative path without / like below :
src="path_to_your_js_files"
I have created Struts2 application using Maven. In this application I have created two namespaces, first is tc and the second one is cmpui. From the JSP page, I am trying to access .css files, but it is giving me 404 error.
Location of JSP page is :
webapp\tc\layout\stylesheets.jsp
Location of CSS file is :
WEB-INF\css\default.css
Code on JSP page is
<link rel="stylesheet" type="text/css" href="../WEB-INF/css/default.css">
Any suggestion please.
You can not access a resources that are under WEB-INF folder. Move your static resources to another place accessible by Struts2 (for example, web root). And use s:url tag to build the URL.
<link rel="stylesheet" type="text/css" href="<s:url value='/css/default.css'/>">
I call an applet through a JSP...where I have to save it? and what the .class and the .java file? in which root in tomcat so when I call it from the JSP to be appeared?
here is the applet call from the jsp
%><%# page language="java"%>
<html>
<body>
<jsp:plugin code="g7appletDialog.class" codebase="" type="applet" width="300" height="200">
<jsp:fallback>Unable to load applet</jsp:fallback>
</jsp:plugin>
<applet code=""g7appletDialog.class"" width="300" heigjt="200"></applet>
</body>
</html><%
The path to your servlet must be relative to your jsp. If you have a jsp in web-inf/admin/pages/index.jsp, then you can place the .class file in directory web-inf/admin/pages/ and just have code="g7appletDialog.class".
In case that you have a central repository for applets, lets say web-inf/admin/applets then you should change the code to code="../applets/g7appletDialog.class".
The ../ gets you one dir back. To go two dirs back use ../../ and so on...
I can't display images in JSP (and can't access other things like external Javascript/jQuery through SRC). The following JSP page just contains one <img> tag that can not display the image located by the SRC.
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="Temp.htm" method="post">
<img src="/images/temp.jpg" alt="Not available">
</form>
</body>
</html>
The images are in /WEB-INF/jsp/images. I have also tried to change the image location and ensure all the times that the path given to SRC is correct still it didn't. The same is possible with the applications without the framework. It works there perfectly. What am I missing here?
First, /WEB-INF is not accessible from the outside.
Second, if you use /images/temp.jpg, the browser will load images from the root of the web server, and not from the root of your web-app (which is deployed under a context path).
Use the JSTL <c:url> tag to generate absolute paths from the root of the web-app:
<img src="<c:url value='/images/temp.jpg'/>" alt=.../>
You cannot access files that are located in /WEB-INF/ directly from the web. The folder is protected from web access.
Locate your image files somewhere else. /images/temp.jpg is a absolute path, however you likely need a relative one. Point your image path to image/temp.jpg and place the images in the /images/ folder directly located under your web root. E.g. WebContent/images or src/main/webapp/images (depending on your web root).
Try put in the webapp directory, not WEB-INF. Obv. dont nest in the jsp dir.
I'm trying to import file from the Header.jsp in my file by using import tag url attribute, but I'm getting runtime error
java.io.FileNotFoundException: http://localhost:8081/latest/header.jsp
The imported file and the importing file in the same web app(latest).
The code of the importing file is:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html><body>
<c:import url="http://localhost:8081/latest/header.jsp" charEncoding="UTF-8" />
<em>Web services Support Group.</em><br><br>
</body></html>
and the code of imported file is:
<em><strong>${param.name}</strong></em><br>
If they're in the same webapp, you don't need a ful URL, you just need the URI relative to the webapp root:
<c:import url="/header.jsp" charEncoding="UTF-8" />
probably you are using the wrong path, where is the file header.jsp? is it in a directory called "latest"? or is "latest" the context path of your application?
skaffman is right, you don't need the full url, but just the url relative to the web app root.