jsp read file where is the current directory

Q

quickcur

I am writing a jsp tag and inside the tag I read a file located on the
server. The jsp and the file are in the same directory. But the server
complains that the file can not be found.

Here is my directory

tomcat->webapp->myapp->myjsp.jsp
->myfile.txt

here is my jsp:

<mytaglib:myTag url="myfile.txt"/>

here is my jsptag
public class myTag extends TagSupport {
String url;

public int doStartTag(){
try{
FileInputStream = new FileInputStream(url));
}catch(IOException){
//this message is print out ...
}
}

public void setUrl(String url){
this.url = url;
}
}
 
A

Andrew Thompson

On 12 Jan 2005 20:51:42 -0800, (e-mail address removed) wrote:
....
here is my jsptag
public class myTag extends TagSupport {
String url;

String path = request.getRealPath(url);
System.out.println( path );
public int doStartTag(){
try{

FileInputStream = new FileInputStream(path));
}catch(IOException){

What is this crap? Why do you waste our time and bandwidth posting
code that is a lie? This code will not compile, so it raises the question.
What is your *real* code?
//this message is print out ...

...What does it print out?
....
 
S

Sudsy

How do you get "request"? Is that page of the TagSupport class?

A quick trip to the javadocs reveals that pageContext (of class
javax.servlet.jsp.PageContext) is a protected field of TagSupport
(actually javax.servlet.jsp.tagext.TagSupport). As such, it is
accessible to subclasses.
Further perusal finds a method with the following signature:
public abstract ServletRequest getRequest();
So it would logically ensue that code such as the following
would work:

HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();

Now I admit I haven't tested this particular code fragment as
all my other experiments with similar constructs have been
successful.
I recommend that you bookmark the following link:
<http://java.sun.com/j2ee/1.4/docs/api/index.html>
Also learn how to dig through the documentation. It's really
easy: just follow the hyperlinks!
 

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,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top