Hi im new in jsp/servlets, i have a basic question about relative or abselute path:
i have the following hierarchy, using netbeans:
Web Pages
| |-Status
| |-clientRequests.jsp
| |-index.jsp
| |-WEB-INF
| |-professional.jsp
index.jsp and the Status folder and WEB-INF folder in root path.
inside the Status folder we have the clientRequests.jsp file.
inside the WEB-INF folder we have the professional.jsp file.
in the index.jsp i have done dispacher to professional.jsp,
inside professional jsp i have <iframe src="Status/clientsRequests.jsp"></iframe>
inside the clientsRequests.jsp i have
<%
response.setHeader("Refresh", "5;url=../index.jsp");
%>
that means that every 5 sec will be refresh to the clientsRequests.jsp file, and then go to the "controller" which is index.jsp.
now what i wanted to be that every 5 min, only the iframe refreshed and not the hole page.
my problem: in the second refresh it gives me 404.
i tried to play with that and i did something ugly like:
String a = (String)session.getAttribute("nav");
if(a == null){
session.setAttribute("nav", "aaa");
response.setHeader("Refresh", "5;url=../index.jsp");
}else{
response.setHeader("Refresh", "5;url=index.jsp");
}
and its working, but i dont want wo leave that like this way...
do you have any suggestions?
thank you!
Somehow your response is setting header for the parent of the iframe too. Put the below line in the of clientsRequests.jsp.
<meta http-equiv="refresh" content="5">
one Alternative would be to move the clientRequests.jsp to the same level as index.jsp.
That way in your code you can always do this
response.setHeader("Refresh", "5;url=index.jsp");
One advantage is with this set up , the <iframe src="Status/clientsRequests.jsp"></iframe> can be added to any of the JSP pages in your application and there is no change/impact in the servlet code
Related
So when I load a view like this:
Address bar reads:
"http://localhost/Mywebsite/private_area"
the view is called from the index function of the controller "private_area", and it works fine. However when I call the page using a function "profile" such that the address bar reads:
"http://localhost/Mywebsite/private_area/profile"
the view loses certain functionality such as the toggle buttons dont work, and the src= doesnt work either. The code for the index function and profile function is identical.
Very confused, any ideas?
Here is some related code:
Controller "Login" Redirects using:
redirect ('private_area');
This calls route
$route['private_area'] = 'private_area';
This calls controller Private Area/Index which has the following code:
$this->load->model("Profiles_model");
$profiledata["fetch_profiledata"] = $this->Profiles_model->fetch_profiledata();
$this->load->view('templates/header_pa');
$this->load->view('pages/page-profile', $profiledata);
$this->load->view('templates/footer');
This works fine and displays the Page-profile view perfectly.
But if I go to another view, and then come back to Page-profile view using
Profile
Which call controller "Private_area" and function "Profile"
function profile()
{
$this->load->model("Profiles_model");
$profiledata["fetch_profiledata"] = $this->Profiles_model->fetch_profiledata();
$this->load->view('templates/header_pa');
$this->load->view('pages/page-profile', $profiledata);
$this->load->view('templates/footer');
}
The main view loads, but the src tags dont work, neither do the toggle buttons.
If you are adding the <?=base_url();?>to your image, and any other path, you'll be good.
In case you are adding variables to your function you will have the same problem all over again.
For example your image should look like this:
<img src="<?=base_ur();?>assets/img/demo/avatar1.jpg">
Hope this helps.
I would say you are using relative paths for your CSS and/or Javascript files without the base_url() in front.
Are you getting any 404s in the developer tools? They usually tell you where the problem is.
A correct way of embedding JS & CSS would be:
<link rel="stylesheet" href="<?=base_url();?>/assets/css/bootstrap.min.css">
<script src="<?=base_url();?>assets/js/bootstrap.min.js"></script>
AnPS: So I was able to solve at least part of the problem like this:
The offending code was:
<img src="assets/img/demo/avatar1.jpg">
It would generate the following error:
GET http://localhost/Mywebsite/private_area/assets/img/demo/avatar1.jpg 404 (Not Found)
As it was reading the Controller - "Private_area" as a folder, so I just added ../ to the offending code
<img src="../assets/img/demo/avatar1.jpg">
I fixed the Toggle Buttons using a similiar approach by adding ../ to the script like this:
<script src="../assets/js/plugins.min.js"></script>
<script src="../assets/js/app.min.js"></script>
This worked, but did I do it right? Or is this just a bad "work-around"?
My first folder is called Tests.
Inside Tests, I've got a HTML file called Tomel.
Using relative link, I stated:
<p> Here's THE IRQI WANNABEE KURD'S Page </p>
Which links Tomel's file to Jasser and it works.
However, to do the reverse and go back from Jasser to Tomel, I stated:
<p> Tomel's Page </p>
But it doesn't work. Help me out here please.
../Test2/Tomel.htm
Tomel's Page inside inside the Test2 directory, but that is where you are looking for it.
From ur information provided
Your directory should look like
Tests/
|
---Tomel.html
---Test2/
|
---Jasser.html
Therefore, if you using the following in Tests/Tomel.html
Test2/Jasser.html
No error as your current directory is Tests/
and Tests/Test2/Jasser.html exists
However, if you are in Tests/Test2/Jasser.html, if you do the following
../
You current directory will become Tests/, therefore, Tomel.html is at the same directory
So the answer for Jasser to Tomel should be
../Tomel.html
I have a project named "Project", and a PDF file caled "file.pdf" located in Project/app/assets/file.pdf. I want to render the PDF on a page called "file.html", located in Project/app/views/static/file.html.
I wrote the following code, but all that displays is an empty white box.
<embed src="../../assets/file.pdf" width="500" height="375" type='application/pdf'>
I'm pretty sure my browser can't find the file. What could I be doing wrong?
UPDATE: I also tried it with an image, placed in app/assets/images/Image.png, like so:
<embed src="../../assets/images/Image.png" width="500" height="375" type='image/png'>
but that doesn't render either.
UPDATE 2: Output from console:
Started GET "/file" for 127.0.0.1 at 2016-02-21 04:48:27 -0600
Processing by StaticController#file as HTML
Rendered static/file.html.erb within layouts/application (63.8ms)
Completed 200 OK in 757ms (Views: 749.4ms | ActiveRecord: 0.0ms)
Started GET "/assets/application.self-e570ac372b74f676a029186250aeeba9bf7016bcd014314d103b5d18b3eb858e.css?body=1" for 127.0.0.1 at 2016-02-21 04:48:28 -0600
Started GET "/assets/pdf-8f705790d319666d8f804cf8809f4d74f036483049ef8c520646d6c98ebedc5f.png" for 127.0.0.1 at 2016-02-21 04:48:28 -0600
Started GET "/assets/Advanced_Reading_Sample.pdf" for 127.0.0.1 at 2016-02-21 04:48:28 -0600
In your controller write,
def file
pdf_filename = File.join(Rails.root, "/assets/file.pdf")
send_file(pdf_filename, :filename => pdf_filename, :disposition => 'inline', :type => "application/pdf")
end
Rename your file.html => file.html.erb and place it under views/controller_name/file.html.erb, also add route to this controller action.
In above setup when you access controller/file/ pdf will shown in the browser(inline).
Try this and see if it works
<iframe src="yourfile.pdf" style="width:100%; height:700px;" frameborder="0"></iframe>
Create folder called pdf (for example) in app/assets and put there your file.pdf then in app/views/static/file.html change src of embed tag to /assets/file.pdf. This should do the trick.
Try, This will help
Click To View
thanks
Mark SykOv
Well I have no idea why my app can't find the file. I just ended up using iframes and the absolute url of the file:
<iframe src="http://www.project.com/file.pdf" style="width:100%;height:100%;"><p>Your browser does not support iframes.</p></iframe>
And finally, the file renders.
The directory structure is as shown below
WEB-INF
|
|-xfolder
|-sample.jsp
|-images/man/upload.html
|
Now how to submit the upload.html form to sample.jsp page
I tried like this in upload.html file
<form method="post" action="../sample.jsp" >
......
.......
</form>
But it not worked.
Help me..
First, if you are uploading files, you need to include enctype= multipart/form-data in your form declaration
Second -and most likely your problem- your form's action is wrong. It should be: action="../../sample.jsp" since you need to go up 2 levels: one for man and one more for images to get to the root where sample.jsp is located.
I have put following code on html page.
<td bgcolor="<%=TableHeaderColor%>"> </td>
However it seems html understand above code and it renders colors. when I change letters in between
<%= %> , I get different colors.
Can someone help me to understand this?
Html doesn't understand a thing, webserver does. Before the page is sent to the client, it's being translated every time and the client (web browser) sees only the generated html result.
In page load : (Server side)
page-load ()
{
if(any condition )
{
TableHeaderColor="Red";
}
else if(any condition )
{
TableHeaderColor="Yellow";
}
else if(any condition )
{
TableHeaderColor="Green";
}
}
Now if you call this TableHeaderColor in your client side as your way , it's changing on your condition ,
It's just a key only
Try this :
<td style="background:<%=TableHeaderColor%>"> </td>
All the asp.net tags you write will be translated once they pass the server.
For example: when you use the tag <asp:hyperlink> it will be translated to <a href="">
try opening the source of a website written in asp, you won't see the asp tags but just html
Is not intepreted by HTML, but by server side page processing.
Ref:
With ASP, code was enclosed within <%... %> tags and page processing
began with the first statement following the first <%> tag. With
ASP.NET, any code that is to be processed as soon as the page is
loaded must be included within the Page_Load intrinsic event. You can
still write code in <%... %> blocks, but it will be executed at render
time (in top-down fashion, as in ASP) after the page is loaded. If you
need to execute initialization code, it should appear in the Page_Load
event, which is raised immediately after the page is loaded by the
ASP.NET engine
Link: http://msdn.microsoft.com/it-it/library/f0111sbh(v=vs.100).aspx