File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Hyper link Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Hyper link Doubt" Watch "Hyper link Doubt" New topic
Author

Hyper link Doubt

vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 218
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.


Thanks
Vipul Kumar
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Haina Minawa
Ranch Hand

Joined: Oct 13, 2011
Posts: 119
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

Joined: Oct 14, 2010
Posts: 218
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

Joined: Jan 10, 2002
Posts: 60050
    
  65

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

Joined: Oct 14, 2010
Posts: 218
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

Joined: Jan 10, 2002
Posts: 60050
    
  65

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

Joined: Oct 14, 2010
Posts: 218
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
Bartender

Joined: Oct 14, 2005
Posts: 18121
    
    8

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

Joined: Oct 14, 2010
Posts: 218
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

Joined: Jan 10, 2002
Posts: 60050
    
  65

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

Joined: Oct 14, 2010
Posts: 218
Bear Bibeault wrote:
Sayin that does not make it true.



I have clearly checked bear.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hyper link Doubt
 
Similar Threads
doubt in EL
doubt related to packages
Doubt
Doubt: jsp:useBean
Doubt in directory creation for files