Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / August 2006

Tip: Looking for answers? Try searching our database.

Application base URL

Thread view: 
zakmck73@yahoo.it - 29 Aug 2006 12:15 GMT
Hi all,

I cannot find an answet to this silly question:

I have a web/module (aka web application) deployed on tomcat.

the application answers to the URL: http://some.host.net:port/myApp/

so, whatever is related to myApp and accessible via http (JSPs,
servlets, static pages), is available at
"http://some.host.net:port/myApp/path/to/whatever".

Now, how may I know what exactly is "http://some.host.net:port/myApp/"
from whitin a JSP or a servlet?

Thanks in advance.
Andrew Thompson - 29 Aug 2006 12:29 GMT
..
> Now, how may I know what exactly is "http://some.host.net:port/myApp/"
> from whitin a JSP or a servlet?

<http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html#
getRealPath(java.lang.String
)>

HTH

Andrew T.
Babu Kalakrishnan - 29 Aug 2006 13:28 GMT
> ..
>
>>Now, how may I know what exactly is "http://some.host.net:port/myApp/"
>>from whitin a JSP or a servlet?
>
> <http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html#
getRealPath(java.lang.String
)>

That would give you only the RealPath relative to the local file system.
(On my local server, it would return "/opt/tomcat55/webapps/myApp/xxx" )

The original question cannot really be answered in a global context. For
instance, the same resource may be available under several variants of
the URL. e.g. A certain page that may be accessible as
"http://127.0.0.1:8080/myApp/index.jsp" from my local machine would only
be accessible with a different hostname/IP when the same is accessed
from another machine on the internet.

This information therefore would be relevant only in the context of a
particular HTTP request, and one can obtain it using :

request.getRequestURL();

BK
ElectricHappiness.com - 30 Aug 2006 05:49 GMT
I actually just tackled a similar problem.  But my hosting company
would not allow me to write to my own domain, I had to write to a
generally accessible temp folder.

Just copy and paste this code into a servlet/JSP page and run it.  It
should reveal which method you should use.

where...
F = first letter of login name
S = second letter of login name
T = third letter of login name

try{
            x = new File("/home/content/F/S/T/FSTloginName/html/temp/1.txt");
            filUploadedFile = new File("/tmp/1.txt");
            filUploadedFile.createNewFile();
            out.println("<br>");
        }catch(Exception e){
            e.getLocalizedMessage();
            out.println("<br><br>");
            out.println(e.getLocalizedMessage());
            out.println("<br>" );
        }

        try{
            x = new File(request.getContextPath() + "./" + "f.txt");
            x.createNewFile();
            out.println("good " + x.getAbsolutePath());
            out.println("         x.getAbsolutePath()<br>");
        }catch(Exception e){
            out.println("<br><br>");
            out.println("BAD 1-> request.getContextPath()./<br>");
            out.println("<br>" + request.getContextPath());
        }
        try{
            x = new File(request.getContextPath() + "/" + "e.txt");
            x.createNewFile();
            out.println("good  " + request.getContextPath() + "<br>");
            out.println("     request.getContextPath(/)<br>");
        }catch(Exception e){
            out.println("<br><br>");
            out.println("BAD 2-> request.getContextPath()/");
            out.println("<br>" + request.getContextPath());
        }

        out.println("<br><br>round 2<br><br>");

        try{
            x = new File(".", "d.txt");
            out.println("good  " + x.getAbsolutePath());
            out.println("       x.getAbsolutePath()<br>" );
            x.createNewFile();
        }catch(Exception e){
            out.println("<br><br>");
            out.println("BAD -> new File(.)");
            out.println("<br>" );
        }

        try{
            x = new File(request.getContextPath(), "c.txt");
            x.createNewFile();
            out.println("good " + x.getAbsolutePath());
            out.println("         x.getAbsolutePath()<br>");
        }catch(Exception e){
            out.println("<br><br>");
            out.println("BAD 1-> request.getContextPath()./<br>");
            out.println("<br>" + request.getContextPath());
        }
        try{
            x = new File(request.getContextPath(),"b.txt");
            x.createNewFile();
            out.println("good  " + request.getContextPath() + "<br>");
            out.println("     request.getContextPath(/)<br>");
        }catch(Exception e){
            out.println("<br><br>");
            out.println("BAD 2-> request.getContextPath()/");
            out.println("<br>" + request.getContextPath());
        }

good luck!

<a href="www.electricHappiness.com">_</a>

> > ..
> >
[quoted text clipped - 19 lines]
>
> BK


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.