jsp:include gives 404 when running - java

My directory tree is like this,
- /index.jsp
- /template/topHeader.jsp
- /accounts/signin.jsp
In my index.jsp I have included the topHeader.jsp like this,
<jsp:include page="template/topHeader.jsp" />
This works fine without any problem. But in the topHeader.jsp I have some <a> tags which I have given paths,
<div class="pull-left">
Hello! Sign in.
</div>
After running, this link gives a 404 which is understandable because the index page is already in the root folder. Now in the future I may have to include this topHeader.jsp almost everywhere.
Browser changes the url like this,
localhost:8084/project/index.jsp
after clicking on the sign in (404)
localhost:8084/accounts/signin.jsp
but the path should be
localhost:8084/project/accounts/signin.jsp
I have also tried including the topHeader.jsp in the following way, but got the same results.
<%# include file="template/topHeader.jsp" %>
So what is the easiest way to give the paths to <a> tags. I'm sorry the question may seem a bit unclear but I don't know how to explain it better.

Use ${pageContext.request.contextPath} to give relative paths to the links,
Sign in

Related

JSP Template in other file - Spring Boot

I'm making a web application in spring boot. I have a lot of views created in JSP, but every view has the same footer and the same menu. Of course I can just copy all menu and footer code and paste it to 30 JSP but I would like to do somethink like this: I have file in which I have something like that menu="HTML CODE WITH MENU", and then in JSP in body section I just put {menu}, and all HTML code is put inside JSP. When I want to change my menu I will just change its code in "menu" variable/string or whatever it will be, and menu in all JSP will change. I tried a few solutions for example with include but it doesn't work. I search scritly the solution I have mentioned. Has anybody got any ideas how I can do this ?
Since you are using JSP you can use the standard JSTL <c:import> tag as explained here. The other options would be to use <%# include #> or <jsp:include>, either of them will work for local files:
<jsp:include page="footer.jsp" />
<%# include file="footer.jsp" %>
<c:import url="footer.jsp" />

Trouble embedding Java applet into an html page

I currently have a relatively simple Java applet which I am trying to embed into an html page. I've looked around, and haven't found a suitable answer. Many answers refer to using the deprecated <applet> tag, and the rest do not seem to work for me.
This is the body of my page. I initially tried using the <applet> tag and it worked, however I was unable to get it to use the full height of the page, and then I found it is deprecated anyways.
I've tried this on Firefox, Chrome, and IE, and it won't work on any of them. It only shows the alternative text.
I did read that the <object> tag only works for IE, but even so it isn't working for me. Likewise, most of the information I found is outdated.
<body>
<object width="500" height="500" data="project">Your browser does not support the <code>object</code> tag.
</object>
</body>
Ive had no problems using the applet tag to get applets to display to a desired width and height. All the Java resources point to using the same tags. I'm no html guru though, so I'm not sure if there's another solution.
<applet code= "myJavaApplet.class" width="600" height="700">textgoeshere</applet>

Can't get all content from webpage with HTMLParser

I am using Jsoup to parse an webpage this one https://daisy.dsv.su.se/servlet/schema.MomentInfoRuta?id=261020&kind=100&nochange=true&allPrio=true&multiple=true&allEx=true
In that webpage i can see something in the browser but when i am trying to parse it with Jsoup
Document doc = Jsoup.parse("https://daisy.dsv.su.se/servlet/schema.MomentInfoRuta?id=261020&kind=100&nochange=true&allPrio=true&multiple=true&allEx=true");
System.out.println(doc);
It will return
<html>
<head></head>
<body>
https://daisy.dsv.su.se/servlet/schema.MomentInfoRuta?id=261020&kind=100&nochange=true&allPrio=trueμltiple=true&allEx=true
</body>
</html>
Which is not all HTML.
Any suggestions how i can solve it or why it is happening?
That looks like they're detecting a crawler, usually via your user agent, and sending different content. Try setting your user agent string to a standard browser's string, and see if that resolves the issue you're having.
One other potential problem, though I don't think it's the issue here, is data loaded in via AJAX will not be downloaded by JSoup. It parses the HTML that gets served up, but it doesn't execute the JavaScript, so it can't get any extra content that comes in later. You might be able to resolve that issue using something like PhantomJS which can process and render HTML, CSS, and JavaScript, and would (in theory) give you the actual HTML you end up seeing in your browser.

Java Applets and html page - embedding multiple applets

I have just started to write applets and so have never embedded in a webpage before. I have 2 applets that on there own run fine however when I try to run the 2 applets in the same page only one is visible. This seems very strange I have tried using the opening and closing foo bar tags for each applet.
These applets have no connection to each other however I also found that the html tags were also ignored after the applet which threw the page design out as well, this has totally baffled me.
The code encasing the applets is
<div class="wholeframe">
<div class="lframe3">
<!-- content for left frame to go here -->
<h2>Basic Java Swing Applet</h2>
<br />
<applet code="org.my.form1.MyApplet" archive="java/form1gui/FormApplet1.jar"
height="60" width="250"/>
</div>
<div class="rframe">
<h2>Basic Java Swing Applet</h2>
<applet code="org.me.hello.MyApplet" archive="java/hello/HelloApplet.jar"
width="350" height="150" />
<!-- right frame div end -->
</div> <!-- whole frame to box 2 frames -->
I would be grateful if someone could advise where I have gone wrong as this should be simple to do and I am sure it is but I cannot seem to work out the issue.
The first thing I'd recommend is validating that 'HTML' with the W3C mark-up validation service. The reason I put the HTML in commas is because whatever that mess is pretending to be, it is not (valid) HTML.
(grumbles) Programmers tend to think that whatever rubbish they put in HTML should work. The real world is somewhat removed from this fantasy land.
Other recommendations:
Post a link to the applet, broken or otherwise. If we are feeling motivated, we can visit it, look at the (entire) HTML, download the Jars or classes, and test solutions.
Ensure the Java Console is opened automatically when loading applets. Without the console information, you are debugging this with 'one arm tied behind your back'.
While debugging, reduce the web page to the minimum. No headers, divs, code, CSS etc. Include that stuff once it is working.
To embed more than one applet in a single web page, put each applet in its own subfolder within the folder that contains the HTML document. Use the APPLET tag's CODEBASE attribute to specify the folder that contains the applet.
For example, to embed the applets 'Aplt1' and 'Aplt2' in the web page defined by the file TestAplt.html, you can set up the following files and subfolders in a folder named Test:
Test/TestAplt.html
Test/Aplt1/<Class files for Aplt1>
Test/Aplt2/<Class files for Aplt2>
For files in this structure, put the following APPLET tags in the file TestAplt.html:
<applet codebase="Aplt1/" code=Aplt1 width=16 height=400 align="left">
<param name=ParamAplt1 value="Aplt1.djr">
</applet>
<applet codebase="Aplt2/" code=Aplt2 width=32 height=400 align="right">
<param name=ParamAplt2 value="Aplt2.djr">
</applet>
Please use this link Multiple applets in a page

pageContext.request.contextPath not working

I'm using Tomcat 6.0.32 and I'm trying to include a JSP file into another, but somehow the file cannot be found (yes, the file exists). Here is the file structure and code:
<jsp:include page="${pageContext.request.contextPath}/templates/header.jsp">
</jsp:include>
WebContent
- folder/caller.jsp
- templates/header.jsp
However, if I use ${pageContext.request.contextPath} outside of that to check if it outputs correctly, it works, does anyone know why this is happening?
I'm not even sure if you can use runtime variables inside a <jsp:include>, but the other problem is that the contextPath refers to the context of the URL being requested from the server, and does not necessarily correspond to your filesystem layout.
Why wouldn't you just use <jsp:include page="templates/header.jsp">?
i completely agree with the above answer however if u have to use it this way then the below code shd work
<c:set var="myContext" value="${pageContext.request.contextPath}"/>
<jsp:include page="${myContext}/templates/header.jsp"> </jsp:include>

Categories