Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hyper link Doubt

 
vipul bondugula
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Haina Minawa
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • 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 bondugula
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 bondugula
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 bondugula
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • 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






 
Paul Clapham
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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 bondugula
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 bondugula
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Sayin that does not make it true.



I have clearly checked bear.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic