How to redirect to a jsp
Hi all, this question seems simple, but I did not figure out how to answer it. In my web.xml I have defined a default servlet. So it can handle requests that does not match other servlets pattern. DefaultServlet / Then in my DefaultServlet, I want to redirect to a jsp page, so I use RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/jsp/index.jsp"); if(dispatcher != null){ dispatcher.forward(request,response); } But doing that, I reenter in my default servlet's doGet method. What I want is rather simple, when a user connect to the site http://server/myapp/, then the request is handled by the default servlet and the jsp page is displayed Thanks for your help Regards Romain - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getRealPath and war file
Sorry, in my previous message, I did not mean the working dir but the temp dir(obtained with javax.servlet.context.tempdir). Romain Mark Thomas wrote: Romain Quilici wrote: Hello Dies, the working directory would be fine, but my images need to be accessible via a url(which is not the case if they are located inside the temp dir) In fact when an image is generated, I push the url inside the client browser, the new url automatically replaces the previous one in a statement like . So I need a url to be able to access my images Push a url to a servlet which then serves the images from the working directory? Mark - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getRealPath and war file
Hello Dies, the working directory would be fine, but my images need to be accessible via a url(which is not the case if they are located inside the temp dir) In fact when an image is generated, I push the url inside the client browser, the new url automatically replaces the previous one in a statement like . So I need a url to be able to access my images Regards Romain Dies Koper wrote: Hello Romain, Is there no way you can use the temporary working directory (javax.servlet.context.tempdir)? I don't know what "pushing inside a client browser" means, but as you mentioned the files are temporary, this sounds like the place to put them.. Also, you won't need to worry about maintaining some extra directory after deployment, and this is a portable solution. Regards, Dies Romain Quilici wrote: Mikolaj Rydzewski wrote: Romain Quilici wrote: My pb is more to write in a given directory(must be accessible with a url), than to read. And I would prefer this directory to be located in my webapp. Use directory outside webapp and then map it with alias, or some kind of dispatcher servlet/filter. It'll help you to redeploy webapp and not to loose uploaded/saved files. Actually, in my application, files are temporary. So even if they are deleted in doesn't matter. What I mean is images are pushed inside a client browser when they are generated, but then are no longer used. I prefer to create the directory within my application, to avoid permissions issues As I understood, context.getRealPath("/"); will return the context of my application, even if my app is deployed within a war(as soon as UnpackWars is set to true in Tomcat). So I can deal with this command. I will provide anyway a mechanism to check if context.getRealPath("/"); is null, in such case the application should take the values from init parameters Regards Romain - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getRealPath and war file
Mikolaj Rydzewski wrote: Romain Quilici wrote: My pb is more to write in a given directory(must be accessible with a url), than to read. And I would prefer this directory to be located in my webapp. Use directory outside webapp and then map it with alias, or some kind of dispatcher servlet/filter. It'll help you to redeploy webapp and not to loose uploaded/saved files. Actually, in my application, files are temporary. So even if they are deleted in doesn't matter. What I mean is images are pushed inside a client browser when they are generated, but then are no longer used. I prefer to create the directory within my application, to avoid permissions issues As I understood, context.getRealPath("/"); will return the context of my application, even if my app is deployed within a war(as soon as UnpackWars is set to true in Tomcat). So I can deal with this command. I will provide anyway a mechanism to check if context.getRealPath("/"); is null, in such case the application should take the values from init parameters Regards Romain - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getRealPath and war file
Mikolaj Rydzewski wrote: Romain Quilici wrote: However, Tomcat creates automatically a directory under webapps to contain war file contents, so I am wondering if Tomcat is using the newly generated directory to load the application(1st case) or the war file (2nd case). In the first case context.getRealPath("/") should return the path to the newly generated directory. In the second case, why does Tomcat generate the directory to contain war file contents? I.e. for performance reasons. One should use context.getResourceAsStream() to read files from both war or expanded directory. Hi all, thanks for the answer. My pb is more to write in a given directory(must be accessible with a url), than to read. And I would prefer this directory to be located in my webapp. Regards Romain - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
getRealPath and war file
Hi all, I know that this question has been asked many times, but still something not clear for me. When an application is deployed as a war file, (as mentioned in the javadoc, or in several messages), context.getRealPath() will return null. However, Tomcat creates automatically a directory under webapps to contain war file contents, so I am wondering if Tomcat is using the newly generated directory to load the application(1st case) or the war file (2nd case). In the first case context.getRealPath("/") should return the path to the newly generated directory. In the second case, why does Tomcat generate the directory to contain war file contents? Thanks for the explanation Regards Romain - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Writing files accessible from a browser
Hi all, thanks a lot for all solutions proposed. I think I am going create the directory within my webapp, but without symbolic link, as my images are temporary files. So even if the directory is deleted it really does not matter Thanks again Romain Li wrote: you are right Moises, if you really wanna write to somewhere within the webapp deploy folder, a better is to make a soft symbol link point to the directory that stores the image, /webapps --- ---> /tmp/images/ so next time update the war, even the folder is removed, the images still at /tmp we can just make a new and make a new link that points to /tmp/images whenever image needs to be written to ... On 8/7/06, Moises Lejter <[EMAIL PROTECTED]> wrote: I had a similar question, earlier... There is another issue here: you are right that WAR files are expanded back into a folder - at least by default - so one could still create a folder within the web app to write to, and which is visible to browsers... Until one deploys an updated WAR file. At that point, tomcat will delete the old expanded WAR folder, in order to create a new one to deploy the new WAR file into - and in the process it will remove all files that were created before. If these files are just transient anyway, then it does not matter... Moises "Li" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > 1. even you deploy as war, later after start tomcat, it will still > generate a folder that actually tomcat uses normally. so in this case, > you still be able to use context path to write > 3. to write, you can always use context path or absolute path > defintion no matter is inside or outside, but after been written and > you wanna view, you have to define as URL, - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Writing files accessible from a browser
I agree with you, but getContext().getRealPath("/"), will return the path to my webapp root, so it means I am going to create my image dir under my webapp, which is fine unless my application is deployed in a war file. In such case I won't be able to write in my webapp. Maybe using String path = getContext().getRealPath("/"); then String imagePath = path+"../imagedir"; would work so I am writting in a separate directory outside my webapp. In case I use war file, this solution might still works Regards Almir Kazazic wrote: Hi, to avoid using absolut paths you can find that out on runtime by getContext().getRealPath("/") - will return your path to the root regards On 8/7/06, Romain Quilici <[EMAIL PROTECTED]> wrote: Hi, Hope I will be clear enough: One part of my web application receives encodes stream that it has to convert to jpg images. When an image is written on the server, it notifies a Servlet which pushes the name (or the url) of the newly generated image inside client browser(thanks to pushlets technology). The Servlet can only push a String (Pushlets requirements). So my problem is where can I write the images, so they can be accessible by a URL. One easy solution, the one I use for testing, is to hardcode in my webapp the directory where the images are written. For instance TOMCAT_HOME\webapps\frames\, and in my jsp to have http://myserver/frames/name.jpg> where name.jpg is pushed by the servlet when this image is generated. However, this solution is not satisfactory, indeed, if I deploy my application in another place, I don't want people to edit my code to change for suitable values. I admit I could use properties or a configuration file to set these value(even if I am not sure it would work in all configuration), anyway I would like to check if using the servletcontext, or other solutions might be more appropriate. As I said a solution with the temp directory would be perfect, if this directory was accessible with a URL Hope it is clear Regards Li wrote: > Hi, > > It is not advisable to make your webapp dir writable, can you tell me > what exactly would you like to achieve so that I may get more info to > help out ... > > > > On 8/7/06, Romain Quilici <[EMAIL PROTECTED]> wrote: >> Hi, >> thanks for the advice, >> But I want to avoid harcoded links such as $APACHE_HOME\httpdocs\images >> or http://yourdomain/images/1.jpg";> in my jsp. >> >> Indeed I don't want to modify these values if I decide Tomcat to run on >> another port, or to install Tomcat in another directory or even OS. That >> is why I am looking for an approach using >> the webapp context, so I don't have to worry about the OS, or the port, >> or whatever configuration. >> Anyway thanks for your help >> Regards >> Romain >> >> Li wrote: >> > Hi, >> > >> > Here are few steps of achieving it (just tested, and it works): >> > 1. use FileOutputStream or any output streaming object to write a >> > image file >> >into the directory >> > in Windows, the path string should look like: >> > "c:\apache_home\httpdocs\images\1.jpg" >> > in unix/linux, the path should look like >> > $APACHE_HOME\httpdocs\images\1.jpg" >> > (assume, you had defined APACHE_HOME, make sure the images folder >> > is read/write >> > only for the user/group that runs tomcat >> > 2. Make sure apache is on ... >> > 3. in your jsp: use >> > e.g. http://yourdomain/images/1.jpg";>click to view >> > >> > >> > Wish it helps >> > >> > On 8/7/06, Romain Quilici <[EMAIL PROTECTED]> wrote: >> >> Thanks for the answer, >> >> this solution was part of my investigation, and was actually the >> first >> >> idea I had. >> >> The problem with this approach is I don't know how to access the >> >> /image_dir/ from within my web application. >> >> Maybe using something like >> >> String path = servletContext.getRealPath("/"); >> >> String imagePath = path+"../image_dir/" >> >> and use the imagePath to create my images, then in my jsp >> something like >> >> >> >> >> >> But I am not sure this approach works in all configurations, >> >> particularly if my webapp is deployed inside a war. >> >> >> >> Thanks >> >> Romain >> >> >> >> Li wrote: >> >> > if you have apache server, you can write file to its home dir, and >> >> > then use >> >> >
Re: Writing files accessible from a browser
Hi, Hope I will be clear enough: One part of my web application receives encodes stream that it has to convert to jpg images. When an image is written on the server, it notifies a Servlet which pushes the name (or the url) of the newly generated image inside client browser(thanks to pushlets technology). The Servlet can only push a String (Pushlets requirements). So my problem is where can I write the images, so they can be accessible by a URL. One easy solution, the one I use for testing, is to hardcode in my webapp the directory where the images are written. For instance TOMCAT_HOME\webapps\frames\, and in my jsp to have http://myserver/frames/name.jpg> where name.jpg is pushed by the servlet when this image is generated. However, this solution is not satisfactory, indeed, if I deploy my application in another place, I don't want people to edit my code to change for suitable values. I admit I could use properties or a configuration file to set these value(even if I am not sure it would work in all configuration), anyway I would like to check if using the servletcontext, or other solutions might be more appropriate. As I said a solution with the temp directory would be perfect, if this directory was accessible with a URL Hope it is clear Regards Li wrote: Hi, It is not advisable to make your webapp dir writable, can you tell me what exactly would you like to achieve so that I may get more info to help out ... On 8/7/06, Romain Quilici <[EMAIL PROTECTED]> wrote: Hi, thanks for the advice, But I want to avoid harcoded links such as $APACHE_HOME\httpdocs\images or http://yourdomain/images/1.jpg";> in my jsp. Indeed I don't want to modify these values if I decide Tomcat to run on another port, or to install Tomcat in another directory or even OS. That is why I am looking for an approach using the webapp context, so I don't have to worry about the OS, or the port, or whatever configuration. Anyway thanks for your help Regards Romain Li wrote: > Hi, > > Here are few steps of achieving it (just tested, and it works): > 1. use FileOutputStream or any output streaming object to write a > image file >into the directory > in Windows, the path string should look like: > "c:\apache_home\httpdocs\images\1.jpg" > in unix/linux, the path should look like > $APACHE_HOME\httpdocs\images\1.jpg" > (assume, you had defined APACHE_HOME, make sure the images folder > is read/write > only for the user/group that runs tomcat > 2. Make sure apache is on ... > 3. in your jsp: use > e.g. http://yourdomain/images/1.jpg";>click to view > > > Wish it helps > > On 8/7/06, Romain Quilici <[EMAIL PROTECTED]> wrote: >> Thanks for the answer, >> this solution was part of my investigation, and was actually the first >> idea I had. >> The problem with this approach is I don't know how to access the >> /image_dir/ from within my web application. >> Maybe using something like >> String path = servletContext.getRealPath("/"); >> String imagePath = path+"../image_dir/" >> and use the imagePath to create my images, then in my jsp something like >> >> >> But I am not sure this approach works in all configurations, >> particularly if my webapp is deployed inside a war. >> >> Thanks >> Romain >> >> Li wrote: >> > if you have apache server, you can write file to its home dir, and >> > then use >> > http:image_name.suffix to view. >> > >> > On 8/7/06, Romain Quilici <[EMAIL PROTECTED]> wrote: >> >> Hi all, >> >> I have been reading several messages about writing files inside a web >> >> application, but I found no answer regarding my problem. >> >> >> >> I need to write files on the file system that can be accessible >> with a >> >> browser(I write images). >> >> >> >> - The most reliable solution I found was to use the webapp's tmp >> >> directory, unfortunately this directory is not accessible with a URL. >> >> >> >> - Another solution would be to write these images under my webapp >> >> root(or in another place under my webapp). But it seems that this >> >> approach does not work with webapps deployed in a war file. >> >> Indeed you cannot write inside wars like this. >> >> >> >> I don't want to rely on some hardcoded solutions. There is still the >> >> possibility to pass the absolute path to the directory (let's say >> >> TOMCAT_HOME/webapps/myimages/) and later, use inside my JSP >> >> , but I think this >> >> solution wo
Re: Writing files accessible from a browser
Hi, thanks for the advice, But I want to avoid harcoded links such as $APACHE_HOME\httpdocs\images or http://yourdomain/images/1.jpg";> in my jsp. Indeed I don't want to modify these values if I decide Tomcat to run on another port, or to install Tomcat in another directory or even OS. That is why I am looking for an approach using the webapp context, so I don't have to worry about the OS, or the port, or whatever configuration. Anyway thanks for your help Regards Romain Li wrote: Hi, Here are few steps of achieving it (just tested, and it works): 1. use FileOutputStream or any output streaming object to write a image file into the directory in Windows, the path string should look like: "c:\apache_home\httpdocs\images\1.jpg" in unix/linux, the path should look like $APACHE_HOME\httpdocs\images\1.jpg" (assume, you had defined APACHE_HOME, make sure the images folder is read/write only for the user/group that runs tomcat 2. Make sure apache is on ... 3. in your jsp: use e.g. http://yourdomain/images/1.jpg";>click to view Wish it helps On 8/7/06, Romain Quilici <[EMAIL PROTECTED]> wrote: Thanks for the answer, this solution was part of my investigation, and was actually the first idea I had. The problem with this approach is I don't know how to access the /image_dir/ from within my web application. Maybe using something like String path = servletContext.getRealPath("/"); String imagePath = path+"../image_dir/" and use the imagePath to create my images, then in my jsp something like But I am not sure this approach works in all configurations, particularly if my webapp is deployed inside a war. Thanks Romain Li wrote: > if you have apache server, you can write file to its home dir, and > then use > http:image_name.suffix to view. > > On 8/7/06, Romain Quilici <[EMAIL PROTECTED]> wrote: >> Hi all, >> I have been reading several messages about writing files inside a web >> application, but I found no answer regarding my problem. >> >> I need to write files on the file system that can be accessible with a >> browser(I write images). >> >> - The most reliable solution I found was to use the webapp's tmp >> directory, unfortunately this directory is not accessible with a URL. >> >> - Another solution would be to write these images under my webapp >> root(or in another place under my webapp). But it seems that this >> approach does not work with webapps deployed in a war file. >> Indeed you cannot write inside wars like this. >> >> I don't want to rely on some hardcoded solutions. There is still the >> possibility to pass the absolute path to the directory (let's say >> TOMCAT_HOME/webapps/myimages/) and later, use inside my JSP >> , but I think this >> solution won't work in many configurations >> >> Thanks a lot for your help >> Regards >> Romain >> >> >> >> >> - >> To start a new topic, e-mail: users@tomcat.apache.org >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> > > - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Writing files accessible from a browser
Thanks for the answer, this solution was part of my investigation, and was actually the first idea I had. The problem with this approach is I don't know how to access the /image_dir/ from within my web application. Maybe using something like String path = servletContext.getRealPath("/"); String imagePath = path+"../image_dir/" and use the imagePath to create my images, then in my jsp something like But I am not sure this approach works in all configurations, particularly if my webapp is deployed inside a war. Thanks Romain Li wrote: if you have apache server, you can write file to its home dir, and then use http:image_name.suffix to view. On 8/7/06, Romain Quilici <[EMAIL PROTECTED]> wrote: Hi all, I have been reading several messages about writing files inside a web application, but I found no answer regarding my problem. I need to write files on the file system that can be accessible with a browser(I write images). - The most reliable solution I found was to use the webapp's tmp directory, unfortunately this directory is not accessible with a URL. - Another solution would be to write these images under my webapp root(or in another place under my webapp). But it seems that this approach does not work with webapps deployed in a war file. Indeed you cannot write inside wars like this. I don't want to rely on some hardcoded solutions. There is still the possibility to pass the absolute path to the directory (let's say TOMCAT_HOME/webapps/myimages/) and later, use inside my JSP , but I think this solution won't work in many configurations Thanks a lot for your help Regards Romain - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Writing files accessible from a browser
Hi all, I have been reading several messages about writing files inside a web application, but I found no answer regarding my problem. I need to write files on the file system that can be accessible with a browser(I write images). - The most reliable solution I found was to use the webapp's tmp directory, unfortunately this directory is not accessible with a URL. - Another solution would be to write these images under my webapp root(or in another place under my webapp). But it seems that this approach does not work with webapps deployed in a war file. Indeed you cannot write inside wars like this. I don't want to rely on some hardcoded solutions. There is still the possibility to pass the absolute path to the directory (let's say TOMCAT_HOME/webapps/myimages/) and later, use inside my JSP , but I think this solution won't work in many configurations Thanks a lot for your help Regards Romain - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Native library not found
Hi all, I have read several message on this issue, and tried many solutions without a real success. Actually I can get it working but I am not happy with that way(explained below). I must admit that it is a mystery how native libraries are found in Tomcat. I am running tomcat 5.5.15 with Axis on Linux(FC5), and want to load a lib.so file. My library libljackj.so is located under /usr/share/labjack When I start tomcat, I get the following message INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/local/jdk1.5.0_06/jre/lib/i386/client:/usr/local/jdk1.5.0_06/jre/lib/i386:/usr/local/jdk1.5.0_06/jre/../lib/i386 So I copied my libljackj.so under /usr/local/jdk1.5.0_06/jre/lib/i386 and it seems to work, the library is loaded. I am not happy with that because I don't want to pollute my Java install dir with external libraries. So I decided to modify the java.library.path I tried two solutions: 1) modifying the /etc/tomcat5/tomcat5.conf and have added as advised in this file: LD_LIBRARY_PATH=/usr/share/labjack:$LD_LIBRARY_PATH export LD_LIBRARY_PATH When Tomcat starts I can see that the directory has been added to the java.library.path: INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/local/jdk1.5.0_06/jre/lib/i386/client:/usr/local/jdk1.5.0_06/jre/lib/i386:/usr/local/jdk1.5.0_06/jre/../lib/i386:/usr/share/labjack: But when trying to load the library I get the standard error java.lang.UnsatisfiedLinkError: no ljackj in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682) at java.lang.Runtime.loadLibrary0(Runtime.java:822) at java.lang.System.loadLibrary(System.java:992) 2)modifying the JAVA_OPTS with JAVA_OPTS="-Djava.library.path=/usr/share/labjack" $JAVA_OPTS When Tomcat starts I can see that the directory is in the java.library.path: INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/share/labjack And again when trying to load the library I get the standard error java.lang.UnsatisfiedLinkError: no ljackj in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682) at java.lang.Runtime.loadLibrary0(Runtime.java:822) at java.lang.System.loadLibrary(System.java:992) It is a real mystery why in the first case the library is loaded successfully while in both last case the lib is not found even if the java.library.path is correct. Thanks a lot for the help you can provide Regards Romain - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]