Richard Elsberry

Ranch Hand
+ Follow
since Mar 14, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Richard Elsberry

I am trying to figure out how to set a string variable that will represent the location on the local file system. This location will be different between development and production so I would like to be able to set this for each location. I've been successful at using jndi to set the datasource for each location so I tried something like this:

<Resource name="jdbc/localPath" auth="Container" type="java.lang.String" value="C:\\work\\swstir\\images\\" />

but I get a "Cannot create resource instance" error message. It seems like either the <TOMCAT-HOME>/conf/web.xml or server.xml is where this should be set but I can't figure out how it's done. Any thoughts?

Thanks,
Richard
13 years ago
Hello,

I'm developing and jsp, with some struts, application and am required to keep a folder of image and pdf files outside the application context and on the server - ie c:\files\load. The files need to reside outside the application so that they are not wiped out when a new war file is deployed. I've done this many times for an images folder or something from within the app but can't figure out how to do this from the file system. Anybody know how this is done?

Thanks,
Richard
13 years ago
JSP
Hello,

I'm developing and jsp, with some struts, application and am required to keep a folder of image and pdf files outside the application context and on the server - ie c:\files\load. The files need to reside outside the application so that they are not wiped out when a new war file is deployed. I've done this many times for an images folder or something from within the app but can't figure out how to do this from the file system. Anybody know how this is done?

Thanks,
Richard
13 years ago
Thanks Bear. That's kinda what I thought and what I've experienced also. I was hoping to save time.
13 years ago
JSP
Anybody heard of a component/taglib that will display a list in a JSP page. You see them everywhere. They usually contain a next and previous link as well as 1-5 out of 50 and additional links like 1 2 3 4 5 to jump ahead in a group of 50. I started to write my own and thought that this must be available somewhere but have been unable to find one. I sorely need something like this for my toolkit.

Thanks in advance,
Richard
13 years ago
JSP
Hi Stefan,

I added the out.flush() to my code. Yes, this code is in a doGet() method of a servlet. It's being called by a struts action:

<a href="/pages/download/download.do">upload</a>

While composing this repsonse I figured out that I could get the download to work if I called the servlet directly and not via the struts action. So it had something to do with how Struts processes request/responses.

I was using the Struts action because I wanted to open the download in a new window. However, I now know that:

resp.setHeader ("Content-Disposition", "attachment;filename=\""+upload.getFileName()+"\"");

the "attachment" parameter of setHeader() accomplishes the same thing. This would be a good thing for folks in the Struts list to know about.

Thanks for the assistance...once again!
Richard
13 years ago
JSP
Bill,

Thanks for your assistance. I rewrote to include the FileInputStream as you suggested but still get the same result. I've made sure that this new code is being tested as the result is exactly the same. I'm missing something obvious but can't put my finger on it.

New code:

HttpSession session = req.getSession();
Upload upload = (Upload)session.getAttribute("uploadRef");
//resp.setContentType ("application/doc");
//resp.setContentType ("application/pdf");
resp.setContentType ("application/x-download");
resp.addHeader ("Content-Disposition", "inline;filename=\""+upload.getFileName()+"\"");

BufferedInputStream bis = null;
ServletOutputStream out = resp.getOutputStream();

try {
File file = new File(upload.getLocalFilePath());
FileInputStream fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
byte[] data = new byte[2048];
int readed = bis.read(data);
while (readed != -1)
{
out.write(data,0,readed);
readed = bis.read(data);
}
}
catch(Exception e){}
if (out != null) out.close();
if (bis != null) bis.close();
13 years ago
JSP
I'm still stumped here. I must be missing something obvious. I've attached my code below.

I am attempting to open a pdf or doc file from the local file system. When the link is clicked on I get the dialogue box asking my to save or open the application. However, when it opens I see what appears to be raw data. Something like this:

�� ��� � > ��

for word docs and a "damaged file" messagee for pdf files.






HttpSession session = req.getSession();
Upload upload = (Upload)session.getAttribute("uploadRef");
//resp.setContentType ("application/doc");
//resp.setContentType ("application/pdf");
resp.setContentType ("application/x-download");
resp.addHeader ("Content-Disposition", "inline;filename=\""+upload.getFileName()+"\"");


try{

BufferedReader bufferedReader = new BufferedReader(new FileReader(upload.getLocalFilePath()));
String line;
PrintWriter out = resp.getWriter();
while ((line = bufferedReader.readLine()) != null)
{
out.println(line);
}
bufferedReader.close();
}
catch(Exception e){

}


I also tried this but get the same result:

//InputStream isStream = null;
//ServletOutputStream sosStream = null;
// try
// {
// //response.flushBuffer();
//isStream = new FileInputStream(new File(upload.getLocalFilePath()));
//sosStream = resp.getOutputStream();
//int ibit = 256;
// while ((ibit) >= 0)
// {
// ibit = isStream.read();
// sosStream.write(ibit);
// }
//
//}
//catch (IOException ioeException)
//{
// }
// sosStream.flush();
// sosStream.close();
// isStream.close();

any help would be greatly appreciated.

Richard
13 years ago
JSP
Ben,

Thanks for the reply. The link you provided is broken. Do you have an alternative?

Richard
13 years ago
JSP
I appologize as I wasn't clear enough in my original post.

I already have the upload portion of the application working. My problem is I don't know how to read a file stored on the local file system, not the applciation's context, and display it in a jsp page.

This was easy when the files where stored inside the application because I only needed to provide a URL to the file. However, these files needed to be moved to a location outside the app and now I'm stuck.
13 years ago
JSP
Hello,

I am writing an application that allows users to upload a file and save it outside of the web application; c:\path to file\file.pdf.
The files will most likely be .doc, .pdf, .txt.

The users also need to be able to click on a hyperlink and display the file in a jsp page. I have not been able to find an answer to this in the archives. Anybody know of a solution?

Thanks,
Richard
13 years ago
JSP
Hello,

I would like to use the BeanUtils.copyProperties method to convert my BO to my TO. However, since my TO is a general container and will hold many more atttributes than my BO, most of the attributes will be null. Null values throw an exception. It sounds like the alternative is to write a converter. Has anybody else dealt with null values and BeanUtils? Or can you point me to a workable solution?

Thanks
Well I posted this just a bit too early. I tried calling the binding using:

InitialContext ctx = new InitialContext();
String bind = (String)ctx.lookup("ascpaString");

and it worked. I'm very excited this will automate deployment some and eliminate my forgetting to change settings. Thought I would post this in case anybody else is looking for a similar solution.

Thanks,
Richard
14 years ago
Hello,

Anybody have any experience using the Name space binding in Websphere App server 5.1.2? I have a URL that needs to be shared in an ear file between several apps. The URL will change between development and production and I'm looking for a way to set that once on the server instead of manually changing it like we currently are. I've entered the admin console Environment --> Naming --> Name Space Bindings and am selecting the String binding type and using the name space ascpaString. I try to call it with:

InitialContext ctx = new InitialContext();
String bind = (String)ctx.lookup("java:comp/env/ascpaString");

I've also tried

java:comp/env/cells/localhost/nodes/localhost/servers/server1//ascpaString

..and just about every other combination I can think of but I get this error message:

javax.naming.NameNotFoundException: Name "comp/env/ascpaString" not found in context "java:"

.. or something similar depending on the string context I use. There's plenty of documentation on what Name Space is but nothing on how to use it. Any help or alternative suggestions would be greatly appreciated.

Thanks
Richard
14 years ago
Hello,

Anyone know how to set up a global config file in websphere similar to how a datasource is set up? I'd like to be able to make a URL available to all apps that can change between test and production.

Thanks, happy 4th
Richard
14 years ago