Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Accessing Server File with Servlets

Reply
Thread Tools

Accessing Server File with Servlets

 
 
Chase Preuninger
Guest
Posts: n/a
 
      09-06-2009
I have a bunch of javascript files contained in an xyz.war file on my
JBoss server. I need a way using servlets (not JSP) to load them into
memory using InputStreams, process them and then send them back out to
the client's web browser. My problem is I can't figure out how to
access these files through a servlet I also want to keep it as dynamic
as possible since I don't know where this code may end up.
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      09-06-2009
Chase Preuninger wrote:
> I have a bunch of javascript files contained in an xyz.war file on my
> JBoss server. I need a way using servlets (not JSP) to load them into
> memory using InputStreams, process them and then send them back out to
> the client's web browser. My problem is I can't figure out how to
> access these files through a servlet I also want to keep it as dynamic
> as possible since I don't know where this code may end up.


If they are in WEB-INF/classes or WEB-INF/lib then you can use
ClassLoader getResourceAsStream to read them.

If not then you can try open it as a file via getServletContext
getRealPath.

Arne
 
Reply With Quote
 
 
 
 
Chase Preuninger
Guest
Posts: n/a
 
      09-06-2009
On Sep 5, 9:06*pm, Arne Vajh°j <(E-Mail Removed)> wrote:
> Chase Preuninger wrote:
> > I have a bunch of javascript files contained in an xyz.war file on my
> > JBoss server. *I need a way using servlets (not JSP) to load them into
> > memory using InputStreams, process them and then send them back out to
> > the client's web browser. *My problem is I can't figure out how to
> > access these files through a servlet I also want to keep it as dynamic
> > as possible since I don't know where this code may end up.

>
> If they are in WEB-INF/classes or WEB-INF/lib then you can use
> ClassLoader getResourceAsStream to read them.
>
> If not then you can try open it as a file via getServletContext
> getRealPath.
>
> Arne


This is the path returned by the getRealPath("") call.

C:\Program Files\jboss-4.2.0.GA\server\default\.\tmp\deploy
\tmp3242525634535.war\

Can't be found and where did the "." come from.
 
Reply With Quote
 
Arved Sandstrom
Guest
Posts: n/a
 
      09-06-2009
Chase Preuninger wrote:
> On Sep 5, 9:06 pm, Arne Vajh°j <(E-Mail Removed)> wrote:
>> Chase Preuninger wrote:
>>> I have a bunch of javascript files contained in an xyz.war file on my
>>> JBoss server. I need a way using servlets (not JSP) to load them into
>>> memory using InputStreams, process them and then send them back out to
>>> the client's web browser. My problem is I can't figure out how to
>>> access these files through a servlet I also want to keep it as dynamic
>>> as possible since I don't know where this code may end up.

>> If they are in WEB-INF/classes or WEB-INF/lib then you can use
>> ClassLoader getResourceAsStream to read them.
>>
>> If not then you can try open it as a file via getServletContext
>> getRealPath.
>>
>> Arne

>
> This is the path returned by the getRealPath("") call.
>
> C:\Program Files\jboss-4.2.0.GA\server\default\.\tmp\deploy
> \tmp3242525634535.war\
>
> Can't be found and where did the "." come from.


A handy way of returning the Javascript file is to include it using a
request dispatcher...this eliminates the InputStream and OutputStream
mechanics.

AHS
 
Reply With Quote
 
Chase Preuninger
Guest
Posts: n/a
 
      09-06-2009
On Sep 6, 12:15*am, Arved Sandstrom <(E-Mail Removed)> wrote:
> Chase Preuninger wrote:
> > On Sep 5, 9:06 pm, Arne Vajh°j <(E-Mail Removed)> wrote:
> >> Chase Preuninger wrote:
> >>> I have a bunch of javascript files contained in an xyz.war file on my
> >>> JBoss server. *I need a way using servlets (not JSP) to load them into
> >>> memory using InputStreams, process them and then send them back out to
> >>> the client's web browser. *My problem is I can't figure out how to
> >>> access these files through a servlet I also want to keep it as dynamic
> >>> as possible since I don't know where this code may end up.
> >> If they are in WEB-INF/classes or WEB-INF/lib then you can use
> >> ClassLoader getResourceAsStream to read them.

>
> >> If not then you can try open it as a file via getServletContext
> >> getRealPath.

>
> >> Arne

>
> > This is the path returned by the getRealPath("") call.

>
> > C:\Program Files\jboss-4.2.0.GA\server\default\.\tmp\deploy
> > \tmp3242525634535.war\

>
> > Can't be found and where did the "." come from.

>
> A handy way of returning the Javascript file is to include it using a
> request dispatcher...this eliminates the InputStream and OutputStream
> mechanics.
>
> AHS- Hide quoted text -
>
> - Show quoted text -


Yet again how do I do that and still what does the "." mean?
 
Reply With Quote
 
Arved Sandstrom
Guest
Posts: n/a
 
      09-06-2009
Chase Preuninger wrote:
> On Sep 6, 12:15 am, Arved Sandstrom <(E-Mail Removed)> wrote:
>> Chase Preuninger wrote:
>>> On Sep 5, 9:06 pm, Arne Vajh°j <(E-Mail Removed)> wrote:
>>>> Chase Preuninger wrote:
>>>>> I have a bunch of javascript files contained in an xyz.war file on my
>>>>> JBoss server. I need a way using servlets (not JSP) to load them into
>>>>> memory using InputStreams, process them and then send them back out to
>>>>> the client's web browser. My problem is I can't figure out how to
>>>>> access these files through a servlet I also want to keep it as dynamic
>>>>> as possible since I don't know where this code may end up.
>>>> If they are in WEB-INF/classes or WEB-INF/lib then you can use
>>>> ClassLoader getResourceAsStream to read them.
>>>> If not then you can try open it as a file via getServletContext
>>>> getRealPath.
>>>> Arne
>>> This is the path returned by the getRealPath("") call.
>>> C:\Program Files\jboss-4.2.0.GA\server\default\.\tmp\deploy
>>> \tmp3242525634535.war\
>>> Can't be found and where did the "." come from.

>> A handy way of returning the Javascript file is to include it using a
>> request dispatcher...this eliminates the InputStream and OutputStream
>> mechanics.
>>
>> AHS- Hide quoted text -
>>
>> - Show quoted text -

>
> Yet again how do I do that and still what does the "." mean?


You can get a request dispatcher directly from the ServletContext,
passing in the String path.

RequestDispatcher getRequestDispatcher(String path)

From the Javadoc, the path should start with "/", and it's with
reference to the _current_ context root.

I wouldn't worry overmuch about the "." in the returned path. The
"C:\Program Files\jboss-4.2.0.GA\server\default" is a hardwired path for
the JBoss server you chose (the default configuration); the subpath
starting with "." is a generated relative path (the ".\" could have been
left off but no harm done that it's there.) JBoss is simply adding the two.

AHS
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      09-08-2009
Chase Preuninger wrote:
> On Sep 5, 9:06 pm, Arne Vajh°j <(E-Mail Removed)> wrote:
>> Chase Preuninger wrote:
>>> I have a bunch of javascript files contained in an xyz.war file on my
>>> JBoss server. I need a way using servlets (not JSP) to load them into
>>> memory using InputStreams, process them and then send them back out to
>>> the client's web browser. My problem is I can't figure out how to
>>> access these files through a servlet I also want to keep it as dynamic
>>> as possible since I don't know where this code may end up.

>> If they are in WEB-INF/classes or WEB-INF/lib then you can use
>> ClassLoader getResourceAsStream to read them.
>>
>> If not then you can try open it as a file via getServletContext
>> getRealPath.

>
> This is the path returned by the getRealPath("") call.
>
> C:\Program Files\jboss-4.2.0.GA\server\default\.\tmp\deploy
> \tmp3242525634535.war\
>
> Can't be found and where did the "." come from.


If your JS files are inside the war then they should be
unpacked in some dir (and the above seems correct if the JS
files are indeed in the root of the war).

Arne
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
accessing servlets using submit buttons ros Java 2 04-03-2007 12:15 PM
Opening files from a web server using Java servlets jonesy Java 3 10-24-2006 01:32 AM
Client/Server/Servlets Design Problem xfan Java 5 08-26-2006 09:59 AM
Java servlets: Hi All! I want to display xml file in browser using servlets datta.saru Software 0 05-15-2006 03:30 PM
jsp, servlets, and perl under one web server ? Eric Osman Java 4 02-23-2004 08:17 PM



Advertisments