| |

VerySource

 Forgot password?
 Register
Search
View: 790|Reply: 9

JSP page resource reference problem

[Copy link]

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-12 23:00:01
| Show all posts |Read mode
Recently I was working on a J2EE project and encountered a strange problem with page resource references:


For example, I have the following resources:
localhost: 8080 / mydir1 / mydir2 / 1.jsp
localhost: 8080 / mydir1 / mydir2 / 2.gif
localhost: 8080 / mydir1 / images / 3.gif

Now I quote 2.gif and 3.gif inside 1.jsp
<td align = "center" background = "2.gif">
<td align = "center" background = "../ images / 3.gif">

This should be fine

But when accessed in a browser, my resources become:
localhost: 8080 / 2.gif
localhost: 8080 / images / 3.gif

Now the only solution I know is to write the full path from localhost:
<td align = "center" background = "/ mydir1 / mydir2 / 2.gif">
<td align = "center" background = "/ mydir1 / images / 3.gif">

This is troublesome, and some things ca n’t be written like this, such as jumps on the same page
Reply

Use magic Report

0

Threads

18

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-4-11 15:00:02
| Show all posts
localhost: 8080 / mydir1 / mydir2 / 1.jsp
Image direct INCLUDE
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-4-12 12:45:01
| Show all posts
There are other resources, cs, js, etc. have this problem
Just go to localhost along with a jump in a page

If the image is included directly, what should I do if I jump to the same page?
Reply

Use magic Report

0

Threads

63

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-4-12 18:00:01
| Show all posts
> For example, jump within the same page

What do you mean?
Reply

Use magic Report

0

Threads

63

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-5-1 15:45:01
| Show all posts
<a name="top"> </a>
............................

<a href="#top"> TOP </a>

The landlord, this kind of problem will not right-click on the HTML code:
<td height = "10" align = "right" colspan = "4"> <font color = "# FF6633"> <b> <a href="#top"> <font color = "# 3366CC"> Top < / font> </a> </ b> </ font> </ td>
Reply

Use magic Report

0

Threads

14

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-5-3 13:30:01
| Show all posts
I suggest you use
<td align = "center" background = "/ mydir1 / mydir2 / 2.gif">
<td align = "center" background = "/ mydir1 / images / 3.gif">
Way to take the path if necessary
You can use multiple methods in the request to get the path, which can achieve your requirements, but a lot of trouble.
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-5-8 14:30:01
| Show all posts
Halo, sorry, old forum error, I replied many times yesterday, but I didn't see the result, I couldn't brush it out, and finally prompted "No more than 3 consecutive postings each time", but I saw it all today.

I will write more details
Just like the "Top" on this page, click to jump to the top of the page
http://community.csdn.net/Expert/TopicView1.asp?id=5274857#top

If it is my application, it becomes:
http://community.csdn.net/#top

All are considered to be from the application root directory, so it is very troublesome.
Reply

Use magic Report

0

Threads

63

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-5-8 22:00:01
| Show all posts
Do you understand
<a name="top">
<a href="#top">
Reply

Use magic Report

0

Threads

63

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-5-9 00:15:01
| Show all posts
# Is html internal positioning
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-5-11 22:00:01
| Show all posts
Thank you all, got it done
It turned out to be the reason:
When I created a new jsp page, I used the default page with a base tag in the head:

<!-Page base URL, used when calculating relative paths->
<base href = "<% = basePath%>">

When creating a new page, the basePath is my application path, so all the resources I referenced point to the application:
<%
String path = request.getContextPath ();
String basePath = request.getScheme () + ": //" + request.getServerName () + ":" + request.getServerPort () + path + "/";
%>
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list