I'm trying to import a JSP using c:import and c:url, but it tells me it couldn't find the file. I tryed using a link to see if it opens the file, and it works fine. So, I suppose the path is correct, but it isnt't working.
My code is like this:
<c:url value="/cabecalho.jsp" var="cabecalho" />
<c:import value="${cabecalho}"></c:import> //page don't open
link //to test the path
If I use <c:url value="cabecalho.jsp" /> it works fine!
What must be happening?
c:url gives You absolute path from internet like http://www.somehost.com . c:import wants relative path to jsp on server.
Related
Is there a way to use root path when refering to includes in JSP?
what I mean is instead of using this method:
<jsp:include page="../inc/header.jsp" />
<jsp:include page="../../inc/header.jsp" />
etc.
To just refer to it like this:
<jsp:include page="jsp/inc/header.jsp" />
Also this is how my project tree looks like
Anybody trying to figure it out here is the answer that I came up with. For some reason intelij IDE tells me that the path cannot be resolved(liar!) looking at my project tree you can include header to any file using this piece of code in your project:
<%# include file="/jsp/inc/header.jsp" %>
This is page content
<jsp:include page="/jsp/inc/footer.jsp" />
In both cases the IDE will tell you that it cannot resolve URL but it works like a charm I hope this helps not only me but future visitors
After a lot of debugging I found that every time I include jsp files like:
<jsp:include page="header.jsp">
when I try do do a HTTP request like: /whatever/request I get the following exception:
javax.servlet.ServletException: File "/whatever/header.jsp" not found
The same exception will happen if I try any path instead of /test above for instance /test/test/request or anything.
When I removed all the directives everything is fine. How do I workaround this.
It looks for jsp relative to context path, in your example it looks for jsp stored in /whatever/header.jsp and it is not there, you should access jsp files by writing their full project's path, otherwise it will look for those jsp in the exact folder you are referring to in your url, if it shows error in folder /list/London, and you include jsp like
<jsp:include page="some.jsp"/>
Then it will look for that file in /list/London/, but if you write
<jsp:include page="/some.jsp"/>
It will look for it in your project's root, meaning under /
I am trying embed a java applet into my webpage. Unfortunately, I can't put my .class file straight into the server so, I was going to read the .class file from a git repository and pointing to it with the archive attribute in my html code.
This is the html code:
<html>
<body>
<applet code="DodgemApplet.class" width="640" height="480" archive="https://github.com/smithg017/repo.git">
</applet>
</body>
</html>
I am still pretty new to html so can someone show me the right way I should be going to get my java applet embedded into my website? Thanks!
Well, there was a hidden property I didn't know about and after much digging I found the property codebase.
I put this:
codebase="https://github.com/smithg017/repo/blob/master/"
right after
code = "DodgemApplet.class"
code is simply the name. by default it will look in the same directory as the html file. In my case, in the Desktop folder. If your class file is elsewhere, reference the folder your class file is in under the codebase property.
Probably a ridiculously easy question here but I must be phrasing it weird in all of my search queries to find similar solutions.
So in my eclipse project I have a folder with some .jsp files in it. In another folder there are some .jpgs . I want to use one of these .jpg files in my .jsp but for some reason cannot get the classpath correct.
I tried right clicking and copying the qualified name and using that path but it wont link correctly for some reason...
my code looks like :
<img src="pikachu.jpg" height="300" />
I've also tried:
<img src="/My_Project_Name/WebContent/images/pikachu.jpg" height="300" />
Note: the Jsp is in:
/My_Project_Name/WebContent/JSP_FOLDER/JSP.jsp
thanks in advance - I know this should be a simple thing...
You need to use
<img src="<%= request.contextPath %>/images/pikachu.jpg" height="300" />
in your JSP.
<% request.contextPath %> will expand to the path under which your web server is serving your app.
Every resource inside of WebContent/ will then be accessible relative to this path.
Related:
http://kodejava.org/how-do-i-get-web-application-context-path-in-jsp/
Similar to Aaron's answer but I believe he has a typo in it (missing an equal sign).
Try this instead, which in my opinion is a little less messy:
<img src="${pageContext.request.contextPath}/images/pikachu.jpg" height="300" />
Aaron's solution would have been:
<img src="<%= request.getContextPath() %>/images/pikachu.jpg" height="300" />
If those don't work, view the page source and copy/paste us what the line looks like when you are using those.
Use
<img src="../images/pikachu.jpg" height="300" />
..(double dots) will move you to parent directory where you are having images folder.
I'm working on a web project using java/ jsp/ servlets/ html/ css in eclipse tomcat, where everything is in the WebContent folder.
In my jsp files... When I try to include other jsp files (using a link like "/fileName.jsp" in jsp include directive) I can do that successfully.
But When I try to include image files (using a link like "/fileName.jpg" in the <img src=""> tag) nothing happens.
Nothing happens because instead of looking in the WebContent folder for image file it looks in the tomcat home directory, i.e.
Instead of looking at "http ://localhost:port/projectName/..." it looks at "http: //localhost:port/..."
Why does it look at the wrong location only with <img src=""> tags but not in <%# /> tag.
A workaround for this is that I start giving absolute paths "/projectName/..." However doing this means I'm hardcoding project name everywhere. This is what I do not want.
Don't include binary content in an ascii output. Why not just use the img tag? If you need to do something to produce a jpeg, I would use a Servlet.
Because the jsp-Links in the website are getting processed and the image links not. Either change the image path or develop an filter that changes the images'links.
Yes Templar, that could have been a way to solve my problem.
However, I simply changed the Context Root of my project from "Project Name" to "/" in Eclipse. This solved my problem.