• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Hyper link Doubt

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

I have a doubt regarding path in jsp files. Suppose i am having a jsp file with hyperlink pointing to the other jsp file in the same directory.

As the other jsp file(suppose named as otherFileName.jsp) is in the same directory can i write only otherFileName.jsp in the url , or else should i write from context path onwards.

I think question is clear.
Please post if you don't understand any..

Thanks & Regards,
Vipul Kumar.
 
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I always use server-relative paths that start with the context path. JSP pages shouldn't be referenced directly in any case -- the link should point to the page controller. And when controllers are used (and they should be) paths are now mapped and concepts like "same folder" no longer have any meaning.

Read this article for more information on controllers.
 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vipul bondugula wrote:

As the other jsp file(suppose named as otherFileName.jsp) is in the same directory can i write only otherFileName.jsp in the url , or else should i write from context path onwards.



Things are simple, within a web app you should use relative paths as suggested by Bear. Even you can use relative paths for files that are not under the same directory, as long as they are within a web app.
 
vipul John
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear,

I tried context path..In jsp pages , i have tried context path using this :



In servlet also d same.In how many ways we can get a context path.

last n funky one: Is there any possibility to get context path in a java class.

Thanks
Vipul kumar
 
Bear Bibeault
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) In a JSP: ${pageContext.request.contextPath}

2) You need a request instance or the servletContext instance to obtain the context path.
 
vipul John
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear,

Another Doubt:

I am uploading an image into a folder. Root_Folder-->uploadedfiles.(Root_Folder , i mean context folder)
In uploaded files , images are stored.

I tried these 2 ways.






The prior one did not work. And the former one did work..Is there any mistake in the prior code..

Will you please explain both code snippets..


Note:- "fileName" i provided is just to avoid confusion and simplicity.

Thanks
Vipul Kumar.
 
Bear Bibeault
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getRealPath() is useless because it returns the file system path to the file. This has little to nothing to do with the URL.
 
vipul John
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear,

May be my doubt is not clear to you.





path is given to a File object. In the prior one, i got FileNotFoundException.

and the latter one did work out. how it worked i don't know.

You quoted that:

getRealPath() is useless because it returns the file system path to the file. This has little to nothing to do with the URL.



File object requires total path and getRealPath() gave it.Thanks for this.


And another one.

how to make my prior one to work. I'm getting FileNotFoundException. how to resolve.Please give suggesion.

I used apache fileupload jar file.Used FileItem to write the file to uploadedfiles folder.


Thanks
vipul kumar






 
Sheriff
Posts: 27451
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, none of that code has anything to do with hyperlinks, so perhaps we should consider it to be a new question and split it into its own thread. However perhaps you think it does and we can carry on in this thread until you see why it doesn't.

As for not finding the file, it would probably help if you spelled the name of the folder correctly. I see two or three different spellings in the code you posted.
 
vipul John
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:
As for not finding the file, it would probably help if you spelled the name of the folder correctly. I see two or three different spellings in the code you posted.



Folder names are all same.

Thanks,
Vipul kumar.
 
Bear Bibeault
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vipul bondugula wrote:

Paul Clapham wrote:
As for not finding the file, it would probably help if you spelled the name of the folder correctly. I see two or three different spellings in the code you posted.



Folder names are all same.


Sayin that does not make it true.
 
vipul John
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:
Sayin that does not make it true.




I have clearly checked bear.
 
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic