How can you know in which directory a JSP file is?

A

Albretch

Say you put the same JSP in

<%CATALINA_BASE%>/webapps/webappName/Dir00/

and

<%CATALINA_BASE%>/webapps/webappName/Dir99/

How could you make the JSP by itself tell apart 'Dir00' from 'Dir99'?

None of these work:

// __
String aPth = null;
File Fl;
try{ Fl = new File("."); aPth = Fl.getCanonicalPath(); }
catch(IOException IOXcptn) { IOXcptn.printStackTrace(); }
System.err.println(" new File(".").getCanonicalPath()=" + aPth);

// __
aPth = (new File(".")).getAbsolutePath();
System.err.println(" (new File(".")).getAbsolutePath=" + aPth);

Is there any work around?
 
A

Albretch

I mean, how can you achieve it at once from the JspInit part of the servlet

You can do it from a request each time by going:

String aRqPath = request.getServletPath();
String aAppPath = application.getRealPath(aRqPath);
String aPath = new File(aAppPath).getParentFile().getPath();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top