Servlets fine, JSP not?

A

Albretch

WHy is it that a code segment like this works fine for a servlet, but not in a JSP?

// __
String aLn;
Process p;
// __ aRealPath=C:\LIUWBT\ROOT\
String aRealPath = SCtxt.getRealPath("/");
System.err.println(" aRealPath=" + aRealPath);

String[] aAr = new String[]{"cmd.exe", "/c", "dir", aRealPath};
try{
// __
p = Runtime.getRuntime().exec(aAr);
// __
DataInputStream DIS = new DataInputStream(p.getInputStream());
BufferedReader BR = new BufferedReader(new InputStreamReader(DIS));
while ((aLn = BR.readLine()) != null) { System.err.println(aLn); }
// __

}catch(IOException i) { i.printStackTrace(); }
 
R

Ryan Stewart

Albretch said:
WHy is it that a code segment like this works fine for a servlet, but not in a JSP?

// __
String aLn;
Process p;
// __ aRealPath=C:\LIUWBT\ROOT\
String aRealPath = SCtxt.getRealPath("/");
System.err.println(" aRealPath=" + aRealPath);

String[] aAr = new String[]{"cmd.exe", "/c", "dir", aRealPath};
try{
// __
p = Runtime.getRuntime().exec(aAr);
// __
DataInputStream DIS = new DataInputStream(p.getInputStream());
BufferedReader BR = new BufferedReader(new InputStreamReader(DIS));
while ((aLn = BR.readLine()) != null) { System.err.println(aLn); }
// __

}catch(IOException i) { i.printStackTrace(); }

It works fine for me (with some minor tweaking). What's the problem? As a
minor point, variable names should be descriptive and always start with a
lowercase letter.
 
A

Albretch

OTOH, you might get better answers from
those that _do_ know if you define what
you mean by the JSP not working 'fine'.

"working 'fine'" means to me (I thought it was obvious :)) that the

System.err.println(aLn);

line prints out this webapps's directory listing

I Hope it is clear now, or you may just include the code in a servlet
and JSP and 'see' what I mean
 
A

Andrew Thompson

"working 'fine'" means to me (I thought it was obvious :))

You assumed it was obvious.
..that the

System.err.println(aLn);

line prints out this webapps's directory listing

I Hope it is clear now, or you may just include the code in a servlet
and JSP and 'see' what I mean

May I? Well thank you!

I may also devote my limited time to helping
people who deserve it the most, and..
 
A

Albretch

Hmmm!

Something very strange (to my understanding) is going on here.

Let me explain to you my intention, so you know why I am doing this.

I jsut finished developing a web app for some school. I have had 'bad
experiences' with their 'admin people' (kids and younsters . . . (I
understand they are learning, but it takes too much of my time))

In order to avoid meddling with the webapps code itself, this time
they will run it from a CD-ROM I will give them with Java + Tomcat +
MySQL

They will still need to extend the app with soem template .html files
simply renamed as .jsp ones on their own, residing in a certain area
of the hard disk drive, say.

C:/_/ROOT/programs/<program_name>/. . .

I set the root context in TC's server.xml as "C:/_/ROOT" and yes! if
I include the code in

"C:/_/ROOT/index.jsp"

it spits the dirrectory listing to System.err

However if I put exactly the same code in

C:/_/ROOT/programs/<program_name>/

or

C:/_/ROOT/jsp/programs/<program_name>/

or

C:/_/ROOT/WEB-INF/classes/programs/<program_name>/

it does not!?

As part of the app's functionality I would like to programatically
know where they put their files.

Notice that I was just checking this, to me, odd behavior. I was
doing some random trials here I could imagine if I read the spex from
cover to cover I could figure this out, but I think, in case I am
right, this, if not a bug, should not be the natural behavior.

What do yu think?
 
A

Albretch

Andrew,

Sorry if I was not clear enough, the problem is not quite clear to
myself anyway, but would you expect for Java to serve you burger :)
if you are asking for a directory listing?

lbrtchx
 
R

Ryan Stewart

Albretch said:
Hmmm!

Something very strange (to my understanding) is going on here.

Let me explain to you my intention, so you know why I am doing this.

I jsut finished developing a web app for some school. I have had 'bad
experiences' with their 'admin people' (kids and younsters . . . (I
understand they are learning, but it takes too much of my time))

In order to avoid meddling with the webapps code itself, this time
they will run it from a CD-ROM I will give them with Java + Tomcat +
MySQL
You mean the webapp is on a CD so they can't change the files?
They will still need to extend the app with soem template .html files
simply renamed as .jsp ones on their own, residing in a certain area
of the hard disk drive, say.

C:/_/ROOT/programs/<program_name>/. . .

I set the root context in TC's server.xml as "C:/_/ROOT" and yes! if
I include the code in

"C:/_/ROOT/index.jsp"

it spits the dirrectory listing to System.err
Okay, so you set the context, put the code in index.jsp, and then go to
something like http://localhost:8080/index.jsp, and it does what you expect?
However if I put exactly the same code in

C:/_/ROOT/programs/<program_name>/

or

C:/_/ROOT/jsp/programs/<program_name>/

or

C:/_/ROOT/WEB-INF/classes/programs/<program_name>/

it does not!?
Now slow down... What is <program_name>? If you move index.jsp from the
previous example to C:/_/ROOT/programs, then you would access it via
http://localhost:8080/programs/index.jsp. And if you move it to
C:/_/ROOT/jsp/programs, it would be at
http://localhost:8080/jsp/programs/index.jsp. However, you can *not* put it
in WEB-INF or any subdirectory of it and access it via a browser. WEB-INF is
totally invisible to the client.
As part of the app's functionality I would like to programatically
know where they put their files.

Notice that I was just checking this, to me, odd behavior. I was
doing some random trials here I could imagine if I read the spex from
cover to cover I could figure this out, but I think, in case I am
right, this, if not a bug, should not be the natural behavior.

What do yu think?
I think I need a bit more information about exactly what you're doing to
cause this problem.
 
A

Albretch

You mean the webapp is on a CD so they can't change the files?

Exactly!

Okay, so you set the context, put the code in index.jsp, and then go to
something like http://localhost:8080/index.jsp, and it does what you expect?

Yes, it does, but only in this case.

Now slow down... What is <program_name>?

<program_name> would be the name of the particular program run by a
teacher. Say Biology for 3rd Graders <bio3rd> or Math as preparation
for the Regents <RegentsMath>

The dir/file structure would be:

C:/_/ROOT/programs/bio3rd/
C:/_/ROOT/programs/RegentsMath/
.. . .

and each of these directories will have an intro.html->.jsp file
describing the program, etc.

If you move index.jsp from the
previous example to C:/_/ROOT/programs, then you would access it via
http://localhost:8080/programs/index.jsp.

Exactly! But when I try to go:

http://localhost:8080/programs/bio3rd/index.jsp

or

http://localhost:8080/programs/bio3rd/intro.jsp

for that matter

TC just hangs indefinitely and in the logs I see:

127.0.0.1 - - [03/May/2004:17:49:22 -0500] "GET /index.jsp?pre_compile
HTTP/1.1" 500 2866
127.0.0.1 - - [03/May/2004:17:50:18 -0500] "GET /index.jsp?pre_compile
HTTP/1.1" 302 -
127.0.0.1 - - [03/May/2004:17:54:02 -0500] "GET
/programs/TAL99/index.jsp?pre_compile HTTP/1.1" 302 -
127.0.0.1 - - [03/May/2004:17:54:34 -0500] "GET
/programs/TAL99/index.jsp?pre_compile HTTP/1.1" 302 -
127.0.0.1 - - [03/May/2004:18:01:50 -0500] "GET / HTTP/1.1" 302 -
And if you move it to
C:/_/ROOT/jsp/programs, it would be at
http://localhost:8080/jsp/programs/index.jsp. However, you can *not* put it
in WEB-INF or any subdirectory of it and access it via a browser. WEB-INF is
totally invisible to the client.

I was just doing some trial nonsense to see what the behavior was.

I still don't see, why would TC just hangs when you try something
like that.

Have you tried to reproduce this problem yourself?
 
R

Ryan Stewart

Albretch said:
If you move index.jsp from the
previous example to C:/_/ROOT/programs, then you would access it via
http://localhost:8080/programs/index.jsp.

Exactly! But when I try to go:

http://localhost:8080/programs/bio3rd/index.jsp

or

http://localhost:8080/programs/bio3rd/intro.jsp

for that matter

TC just hangs indefinitely and in the logs I see:

127.0.0.1 - - [03/May/2004:17:49:22 -0500] "GET /index.jsp?pre_compile
HTTP/1.1" 500 2866
127.0.0.1 - - [03/May/2004:17:50:18 -0500] "GET /index.jsp?pre_compile
HTTP/1.1" 302 -
127.0.0.1 - - [03/May/2004:17:54:02 -0500] "GET
/programs/TAL99/index.jsp?pre_compile HTTP/1.1" 302 -
127.0.0.1 - - [03/May/2004:17:54:34 -0500] "GET
/programs/TAL99/index.jsp?pre_compile HTTP/1.1" 302 -
127.0.0.1 - - [03/May/2004:18:01:50 -0500] "GET / HTTP/1.1" 302 -
What log did you get this from? A 500 status code indicates an internal
server error. Normally in these circumstances, Tomcat will show you a
stacktrace. 302 is a temporary redirect. If you've got the directories
mentioned above, can you go to http://localhost:8080/programs/bio3rd/ (or
the other) and see a directory listing? If not, the problem isn't with your
JSP. It's with your Tomcat setup somewhere. Have you looked at your Tomcat
localhost logs?
 
A

Albretch

Hi Ryan,

well, I decided to change the way I was doing things altogether,
cleared all caches, renewed all background data, . . . then tried the
same thing and it works! so I had some kind of misconfiguration I have
to time to find out about now.

I think it is architecturally better if I use getResourceAsStream
from a servlet to read the writable/editable areas of the application.

Thanks

"Ryan Stewart" <[email protected]> wrote in message . . .
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top