Determine path of servlet & file resource
I've got a servlet that is collecting data from an HTML form, and writing it to a csv file. Right now, I need to feed the servlet this long pathname so that it can find the file I want to write to. The file is kept in the same place as the .class file of the servlet, btw. I thought I could use paths relative to the .class file, but it's not working when I create a new File object. In this same servlet, creating a FileWriter object has no problem spotting a file jsut by passing the file name which is also kpt with the .class file, no path needed. e.g.
Where path is set up as a long string with an absolute path on the server, this works
File f = new File(path, "Test.csv");
p = new PrintWriter(new BufferedWriter(new FileWriter(f, true)));
^^^ I'm then wrapping it in Buffer & Writer and appending to it)
Why does the following work without a path being supplied??
FileWriter fw = new FileWriter("Test.txt");
And, if the answer won't help me, is there some way I can discover the relative path so that when the code is moved to another server, if the path changes it will still work? I've tried getContextPath, getRealPath, etc. on the request object, but none equal the true path. What am I missing?
- Bob
Both the "File" and "FileWriter" classes resolve the relative names in the same way. My guess is that your codeFileWriter fw = new FileWriter("Test.txt");APPEARS to work , because FileWriter creates the file if not found.
As far as your question of finding the directory of the servlet, i would not recommend it because it if your deploy your application as a archive, you won't really know where the application server will explode your archive. If you really want to store the data in a file, pass the path as a parameter to the servlet.
Similar Messages
-
Relative path for servlet property file.
I have the following java file. When I use the absolute path for the configFile, it works. I would like to know how I could use it as relative path as in installation, the name of the directory could change.
How do I fix the problem? Thank you.
---------------------- LoadProperties.java ----------------
import java.util.*;
import java.io.*;
public class LoadProperties {
private String driver="";
private String dbURL="";
private String login="";
private String password="";
static public void main(String[] args) {
LoadProperties lp = new LoadProperties();
} // main
public LoadProperties() {
//String configFile = "C:/1LMS/web-app/WEB-INF/config/db.properties";
String configFile = getClass().getResource("config/db.properties").toString(); <--- This line could not find the db.properties file.
Properties Prop = new Properties();
try {
FileInputStream configStream = new FileInputStream(configFile);
Prop.load(configStream);
configStream.close();
} catch(IOException e) {
System.out.println("Error: Cannot laod configuration file ");
driver =Prop.getProperty("driver");
dbURL = Prop.getProperty("dbURL");
login = Prop.getProperty("login");
password = Prop.getProperty("password");
printResult();
} //Load Property
private void printResult() {
System.out.println("Driver = " + driver);
System.out.println("dbURL = " + dbURL);
System.out.println("Login = " + login);
System.out.println("PSWD = " + password);
} // classhi there,
had the same problem... you need to use following API:
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)
In your case something like that:
// get the servlet context
ServletContext context = getServletContext();
// directory name where the file is located
String realPath = context.getRealPath("/config");
// get real path to your file
String propertyPath = real+"filename.txt";
hope that helps!!
minu -
Getting absolute path of a file in a webapp without using servlet/JSP
Hi all,
I need a small clarification. Is it possible to reterive the absolute path of a file present in a tomcat web application without using Servlet/JSP. I have a normal java class which uses this file to read the configuration parameters. I like to know whether I need to create a seperate servlet which will read the parameters from web.xml.Hi all,
I need a small clarification. Is it possible to
reterive the absolute path of a file present in a
tomcat web application without using Servlet/JSP. What if the file is in a WAR? What do you do then?
I
have a normal java class which uses this file to
read the configuration parameters. There are other, better ways to do this.
I like to know
whether I need to create a seperate servlet which
will read the parameters from web.xml.What do you really want it for? You shouldn't need an absolute path. Use the class loader to get an InputStream.
% -
Creating A File Resource Using Tomcat JNDI
Hi guys,
My problem is that I am creating a web service and I cannot get to a properties file without creating an absolute reference to that file. If I was creating a servlet I would simple use getServletContext() method to get a relative reference to it. However since it is an axis web service i have to deploy my applications in the WEB-INF/services directory, and because it does not interact with the axis servlet I cannot use getServletContext(). So i thought I could create a JNDI file resource reference in the tomcatHome/conf/context.xml file, similar to how I created a JNDI connection pool. The resouce definition looks like this;
<Resource name="resource/dialogueEngineConfig" auth="Container"
type="java.io.File"
url="file:/Applications/apache-tomcat-5.5.1/webapps/axis2/META-INF/DialogueEngine.properties">
</Resource>now I tried to access the resource in my code like this;
// Obtain our environment naming
Context envCtx = (Context) new InitialContext().lookup("java:comp/env");
// Look up our file
File f = (File) envCtx.lookup("resource/dialogueEngineConfig");However I get a NamingException; 'Cannot create resource instance'
I don't understand why I cant create a file resource in JNDI, it seems like a simple enough thing to do. Am I doing something wrong or missing something? Any help would be greatly appreciated.
ThanksHello xalien,
I have the same problem. I need to access external xml config file via JNDI from my servlet, running on Tomcat 5.0.28. Have you manage to define an URL resource? If so, please provide an example how to do it. Many thanx. -
How to place a servlet file in Tomcat 5.0?
Hi,
i'm using Apache Tomcat 5.0 as myweb server.i don't know how to set the class path and where to place my servlet and html files,and how to run my servlet file.if anybody knows plz give me a detailed description abt this topic.Look at the directory structure of your Tomcat installation directory. You will see a webapps directory under that. The Tomcat installation comes with samples ready to run. Look at those and create a similar directory structure under webapps for your application. I don't think you need to worry about classpath. Tomcat should be taking care of all that if you create the proper directory structure.
You run your servlet by specifying a url like:
localhost:8080/servlets-examples/from a browser. This assumes that your installation is using port 8080 which I think is the norm for Tomcat. Here "servlets-examples" is the name of the directory you created. Actually Tomcat 5.0 comes with a "servlets-examples" application. This would be a good directory to look at. You could also run their examples to get a feel for it.
If you are new to servlets, you'll probably have to get a book that explains how things need to be set up. You'll need to create a web.xml for your application. If you look at the servlets-examples directory under webapps, you'll see that it has a WEB-INF directory under it and that directory contains a file called web.xml as well as a sub-directory called classes. This structure is standard accross all application servers because it corresponds to the war (wars are specialized types of jars for web apps) file standard. -
How to get the complete path of the file that is selected using FormFile
i m working on struts..
i hv used FormFile like
<html:file property="xsdpath" value="Browse" />
need to get the whole path that i will select using browse button
for example d:\foldername\filename.java
but FormFile Api has a method getFileName(); which returns the filename, for getting the absolute path wat has to be done.
please reply bak soon
thanks in advancehere i use formfile <html:file> just to allow the
user to select a xml file .
so i need to get the whole path of the selectedfile
to parse the xml file.No you dont.
You would definitely benefit from further reading on
file upload.
<html:file> tag renders an HTML <input> element of
type file.
When a user uploads a file, this file is sent as a
stream of data, which a program (jsp/servlet) on the
server, reads and stores the data back in the form
of a file on the server.
Any server program that needs to parse the file,
should do so on the file stored on the server.
There's no point in knowing the absolute path of the
file on the client machine. If a server program can
parse a file on the client machine, why upload the
file in first case ? Get the drift ?
i also want to show my user the path he hadselected.
If you have such a requirement, then yes.
But it sounds weird to me. If you see my response
above, you will realize that the server has a copy of
the client's file uploaded and then parsed. What if
the client has changed his file after upload ?
cheers,
ram.I also have a requirement to get the whole filepath of the file selected and place this information into a table. From FormFile I can only retreive the absolute filename
Any suggestions would be helpful.
Thanks, dam -
How to find the physical path of a file
Usually, one can use absFileNmae() method to find the path of a file in Java. The problem is that it may only return a mapped path when a Servlet or JSP is running in a special server. For example, when I run a servlet "MyProgram" in JRun, absFileName() only returns "c:\JRun\jsm-default\MyProgram", which is just a mapped path, not a real physical path.
By the way, in ASP, one can use server.mapPath("MyASPProgram.asp") to obtain the real physical path of the file.
Your solution is welcome.
YCUsually, one can use absFileNmae() method to find the path of a file in Java. The problem is that it may only return a mapped path when a Servlet or JSP is running in a special server. For example, when I run a servlet "MyProgram" in JRun, absFileName() only returns "c:\JRun\jsm-default\MyProgram", which is just a mapped path, not a real physical path.
By the way, in ASP, one can use server.mapPath("MyASPProgram.asp") to obtain the real physical path of the file.
Your solution is welcome.
YC -
Mapping paths to servlets doesn't work anymore in SP5 ??
Hello,
see subject.
I have a small web application which is contained in a WAR-file named
"httpdump.war". Its deployment descriptor (web.xml) maps the servlet
httpdump.HttpDumpServlet to the path /servletpath/* with the following
XML statements:
<servlet>
<servlet-name>HttpDumpServlet</servlet-name>
<display-name>The HTTP Dump Servlet</display-name>
<servlet-class>httpdump.HttpDumpServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HttpDumpServlet</servlet-name>
<url-pattern>/servletpath/*</url-pattern>
</servlet-mapping>
In weblogic.properties, I have:
weblogic.httpd.webApp.httpdump=httpdump.war
The WAR-file is structured as follows:
$ jar tf httpdump.war
META-INF/
META-INF/MANIFEST.MF
WEB-INF/classes/httpdump/HttpDumpServlet.class
WEB-INF/web.xml
dummy.jsp
$
Now a request like http://host:port/httpdump/servletpath/xyz should be
directed to my servlet, right?
This works flawlessly in WLS 5.1 SP 3. With SP 5, I get the following:
Sat Aug 26 15:58:54 CEST 2000:<E> <WebAppServletContext-httpdump> Error loading servlet: httpdump.HttpDumpServlet
java.lang.ClassNotFoundException: httpdump.HttpDumpServlet
at weblogic.boot.ServerClassLoader.findLocalClass(ServerClassLoader.java:355)
at weblogic.boot.ServerClassLoader.loadClass(ServerClassLoader.java:111)
at java.lang.ClassLoader.loadClass(ClassLoader.java:243)
at weblogic.utils.classloaders.GenericClassLoader.parentLoadClass(GenericClassLoader.java:503)
at weblogic.utils.classloaders.GenericClassLoader.reallyLoadClass(GenericClassLoader.java:366)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:182)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:156)
at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:371)
at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:187)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:118)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:760)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:707)
at weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextManager.java:251)
at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:369)
at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:269)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:135)
Sat Aug 26 15:58:54 CEST 2000:<E> <WebAppServletContext-httpdump> Servlet failed with ServletException
javax.servlet.ServletException: Servlet class: httpdump.HttpDumpServlet could not be loaded - the requested class wasn't found in the classpath
at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:379)
at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:187)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:118)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:760)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:707)
at weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextManager.java:251)
at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:369)
at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:269)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:135)
So, it seems the WLS has interpreted the <servlet-mapping> tag in the
DD correctly, but is then looking for the servlet class in the wrong
places..?
My system configuration:
$ java weblogic.Admin t3://localhost:7001 VERSION
WebLogic Build: 5.1.0 Service Pack 5 08/17/2000 07:21:55 #79895
$ uname -a
Linux localhost.localdomain 2.2.14 #1 Wed Aug 16 01:57:42 CEST 2000 i686 unknown
$ java -version
java version "1.2.2"
Classic VM (build 1.2.2-L, green threads, nojit)
$
Any hints?
Thanks,
Olaf
Olaf Klischat | TU Berlin computer science
Oberfeldstrasse 132 |
12683 Berlin, Germany |
phone: +49 30 54986231 | eMail: [email protected]
Hi,
we jared our servlets up and placed them in /WEB-INF/lib/....jar. The
mapping is working without any problems.
Daniel Hoppe
-----Original Message-----
From: Kumar Allamraju [mailto:[email protected]]
Posted At: Saturday, August 26, 2000 7:57 PM
Posted To: servlet
Conversation: mapping paths to servlets doesn't work anymore in SP5 ??
Subject: Re: mapping paths to servlets doesn't work anymore in SP5 ??
Yes, this is already a known problem in SP5.
Fix will be available in the upcoming service packs.
I guess the workaround is to put servlet classes in servlet classpath.
Sorry about the regression.
Kumar
Olaf Klischat wrote:
> Hello,
>
> see subject.
>
> I have a small web application which is contained in a WAR-file named
> "httpdump.war". Its deployment descriptor (web.xml) maps the servlet
> httpdump.HttpDumpServlet to the path /servletpath/* with the following
> XML statements:
>
> <servlet>
> <servlet-name>HttpDumpServlet</servlet-name>
> <display-name>The HTTP Dump Servlet</display-name>
> <servlet-class>httpdump.HttpDumpServlet</servlet-class>
> </servlet>
>
> <servlet-mapping>
> <servlet-name>HttpDumpServlet</servlet-name>
> <url-pattern>/servletpath/*</url-pattern>
> </servlet-mapping>
>
> In weblogic.properties, I have:
>
> weblogic.httpd.webApp.httpdump=httpdump.war
>
> The WAR-file is structured as follows:
>
> $ jar tf httpdump.war
> META-INF/
> META-INF/MANIFEST.MF
> WEB-INF/classes/httpdump/HttpDumpServlet.class
> WEB-INF/web.xml
> dummy.jsp
> $
>
> Now a request like http://host:port/httpdump/servletpath/xyz should be
> directed to my servlet, right?
>
> This works flawlessly in WLS 5.1 SP 3. With SP 5, I get the following:
>
> Sat Aug 26 15:58:54 CEST 2000:<E> <WebAppServletContext-httpdump>
Error loading servlet: httpdump.HttpDumpServlet
> java.lang.ClassNotFoundException: httpdump.HttpDumpServlet
> at
weblogic.boot.ServerClassLoader.findLocalClass(ServerClassLoader.java:35
5)
> at
weblogic.boot.ServerClassLoader.loadClass(ServerClassLoader.java:111)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:243)
> at
weblogic.utils.classloaders.GenericClassLoader.parentLoadClass(GenericCl
assLoader.java:503)
> at
weblogic.utils.classloaders.GenericClassLoader.reallyLoadClass(GenericCl
assLoader.java:366)
> at
weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoa
der.java:182)
> at
weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoa
der.java:156)
> at
weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl
.java:371)
> at
weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.jav
a:187)
> at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.
java:118)
> at
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContex
tImpl.java:760)
> at
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContex
tImpl.java:707)
> at
weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletCon
textManager.java:251)
> at
weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:3
69)
> at
weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:269)
> at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:135)
>
> Sat Aug 26 15:58:54 CEST 2000:<E> <WebAppServletContext-httpdump>
Servlet failed with ServletException
> javax.servlet.ServletException: Servlet class:
httpdump.HttpDumpServlet could not be loaded - the requested class
wasn't found in the classpath
>
> at
weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl
.java:379)
> at
weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.jav
a:187)
> at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.
java:118)
> at
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContex
tImpl.java:760)
> at
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContex
tImpl.java:707)
> at
weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletCon
textManager.java:251)
> at
weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:3
69)
> at
weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:269)
> at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:135)
>
> So, it seems the WLS has interpreted the <servlet-mapping> tag in the
> DD correctly, but is then looking for the servlet class in the wrong
> places..?
>
> My system configuration:
>
> $ java weblogic.Admin t3://localhost:7001 VERSION
> WebLogic Build: 5.1.0 Service Pack 5 08/17/2000 07:21:55 #79895
>
> $ uname -a
> Linux localhost.localdomain 2.2.14 #1 Wed Aug 16 01:57:42 CEST 2000
i686 unknown
>
> $ java -version
> java version "1.2.2"
> Classic VM (build 1.2.2-L, green threads, nojit)
> $
>
> Any hints?
>
> Thanks,
> Olaf
> --
> Olaf Klischat | TU Berlin computer science
> Oberfeldstrasse 132 |
> 12683 Berlin, Germany |
> phone: +49 30 54986231 | eMail: [email protected]
-
how 2 get the path of a file Using jsp
i have tried getPath...but i'm geting the error
The method getPath(String) is undefined for the type HttpServletRequest
any idea how 2 get the path of a fileYou need ServletContext#getRealPath().
API documentation: http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String) -
How 2 get the path of a file Using jsp
how 2 get the path of a file Using jsp
i have tried getPath...but i'm geting the error
The method getPath(String) is undefined for the type HttpServletRequest
any idea how 2 get the path of a fileYou need ServletContext#getRealPath().
API documentation: http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String) -
F4 Help to get the path for a File source directory
There are numerous function modules for browsing a particular file in desktop and getting the file path (including the fine name) , like F4_FILENAME , KD_GET_FILENAME_ON_F4 , WS_FILENAME_GET etc. But can anyone tell me how to fetch only the directory path to the field were the F4 help is given. Actually the filename has to come in some other field in the selection screen. Is there separate funtion modules for these OR will changing parameters in the above function modules work?
Pls Help....
Also are there function modules for providing F4 help for getting the path to a file in application directory?Try this method CL_GUI_FRONTEND_SERVICES.
It is a Global CLASS which is having different methods for different purposes
see the documentation of it and use the methods of it
see
CL CL_GUI_FRONTEND_SERVICES
Short Text
Frontend Services
Functionality
The class CL_GUI_FRONTEND_SERVICES contains static methods for the following areas:
File functions
Directory functions
Registry
Environment
Write to / read from clipboard
Upload / download files
Execute programs / open documents
Query functions, such as Windows directory, Windows version, and so on
Standard dialogs (open, save, directory selection)
Example
Determine the temp directory on your PC:
DATA: TEMP_DIR TYPE STRING.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_TEMP_DIRECTORY
CHANGING
TEMP_DIR = TEMP_DIR
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2.
IF SY-SUBRC 0.
Error handling
ENDIF.
flush to send previous call to frontend
CALL METHOD CL_GUI_CFW=>FLUSH
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR = 2
OTHERS = 3.
IF SY-SUBRC 0.
Error handling
ENDIF.
WRITE: / 'Temporary directory is:', TEMP_DIR.
Notes
The class CL_GUI_FRONTEND_SERVICES is based on the Control Framework. See the documentation for more information, in particular on CL_GUI_CFW=>FLUSH which must be called after many CL_GUI_FRONTEND_SERVICES methods.
Migration Information
The old file transfer model was based on function modules of the function group GRAP. The old features have been replaced by the class CL_GUI_FRONTEND_SERVICES. The following list contains the old function modules (italic) and the new methods (bold) that replace them:
CLPB_EXPORT
CLIPBOARD_EXPORT
CLPB_IMPORT
CLIPBOARD_IMPORT
DOWNLOAD
GUI_DOWNLOAD, dialog replaced by FILE_SAVE_DIALOG
PROFILE_GET
No replacement, use REGISTRY_* methods instead
PROFILE_SET
No replacement, use REGISTRY_* methods instead
REGISTRY_GET
REGISTRY_GET_VALUE, REGISTRY_GET_DWORD_VALUE
REGISTRY_SET
REGISTRY_SET_VALUE, REGISTRY_SET_DWORD_VALUE
UPLOAD
GUI_UPLOAD, dialog replaced by FILE_OPEN_DIALOG
WS_DDE
Obsolete: This function is no longer supported.
SET_DOWNLOAD_AUTHORITY
Obsolete: This function is no longer supported.
WS_DOWNLOAD
GUI_DOWNLOAD
WS_DOWNLOAD_WAN
Obsolete: This function is no longer supported.
WS_EXCEL
Obsolete: This function is no longer supported.
WS_EXECUTE
EXECUTE
WS_FILENAME_GET
FILE_SAVE_DIALOG, FILE_OPEN_DIALOG
WS_FILE_ATTRIB
FILE_SET_ATTRIBUTES, FILE_GET_ATTRIBUTES
WS_FILE_COPY
FILE_COPY
WS_FILE_DELETE
FILE_DELETE
WS_MSG
Obsolete: This function is no longer supported.
WS_QUERY
CD (current directory)
DIRECTORY_GET_CURRENT
EN (read/write environment)
ENVIRONMENT_GET_VARIABLE
ENVIRONMENT_SET_VARIABLE
FL (determine file length)
FILE_GET_SIZE
FE (check if file exists)
FILE_EXIST
DE (check if directory exists)
DIRECTORY_EXIST
WS (determine Windows system)
GET_PLATFORM
OS (operating system)
GET_PLATFORM
WS_UPLDL_PATH
Obsolete: This function is no longer supported.
WS_UPLOAD
GUI_UPLOAD
WS_VOLUME_GET
Obsolete: This function is no longer supported.
Reward points if useful. -
Hi,
this question might seem very trivial and you think that I should find it by searching on the internet but as often: you never find exactly what you want when you really need it.
So, here is my question:
I have a dynamic web project in eclipse and in my jsp a xsl file has to be loaded. I copied the file under the WebContent folder and within my jsp I tried the following:
if(new File("transformation.xsl").exists())
out.println("<h1>exists</h1>");
else
out.println("<h1>file does not exist</h1>");but everytime the file is not found. I dont know how to fix it - of course I tried some path combinations but it did not work.
Thanks for answers in advance!
Edited by: Cinimood on Sep 29, 2008 8:12 AMCinimood wrote:
new File("transformation.xsl")
Do you realize that this will look for the file in the current working directory? There is no absolute thumb rule where exactly it is. You should also never rely on the operating system's or application server's configuration of the working directory. The file system operates completely independent from the web application. If you're interested though, just call File#getPath() to see what its absolute path is after all.
There are two general approaches to access (external) file resources inside a web application, independent of where it is installed.
1) Use ServletContext#getRealPath(). Place the resource somewhere in the webcontent. E.g. in the /WEB-INF. Then pass its path as a relative web path to ServletContext#getRealPath() to convert it to an absolute file system level path. Finally use it in File().
2) Use ClassLoader#getResource(). Place the resource somewhere in the classpath or add its path to the classpath. Then use ClassLoader#getResource() to get its absolute URL. Finally use it in File(). Or just check if it is null or not. If you actually need an InputStream of it after all, then you can also just use ClassLoader#getResourceAsStream(). -
HTML file reference to a Servlet file...Very Urgent
Hi
i am new to JSP and servlet..........
i already build a servlet file.
I am submitting the html form to this servlet file.
but i encounter problem........
<form method="POST" action="../servlet/SearchSong">
SearchSong(my class name)
but i kept getting error "the requested resource is not available"
what wrongs ...please helpToo little information ...
Case 1. Define your servlet mappings in your web.xml file and check if you are giving the correct URL for the servlet in your form action
Case 2. Each server has a default folder for servlets. I guess you are trying to do something like this. In this case you have to look at your server documentation on the URL to be used to invoke servlets. -
Accessing an ejb from a servlet gives resource not allowed exception
hi friends,
i deployed a bean in weblogic server calling from within a servlet. this bean is used to retrieve a database connection and returns to the servlet. i have done all the resource references lookups everything and also the bean is deployed successfully, but when i run the servlet i didn't get even the println messages. it gives resource not allowed message.
here is the deployment descriptor is correct ? if anything wrong or missed, please mention and try to give me the solution.
web.xml
<web-app>
<servlet>
<servlet-name>TestConnection</servlet-name>
<display-name>TestConnection</display-name>
<servlet-class>tms.com.ejb.TestConnection</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestConnection</servlet-name>
<url-pattern>TestConnection</url-pattern>
</servlet-mapping>
<resource-ref>
<res-ref-name>tmsPool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<env-entry>
<env-entry-name>tmsDataSource</env-entry-name>
<env-entry-value>tmsPool</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
<env-entry>
<env-entry-name>TMS_DBConnectionBean</env-entry-name>
<env-entry-value>java:comp/env/ejb/TMS_DBConnectionBean</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
<ejb-ref>
<ejb-ref-name>ejb/TMS_DBConnectionBean</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>tms.com.ejb.TMS_DBConnectionHome</home>
<remote>tms.com.ejb.TMS_DBConnection</remote>
<ejb-link>TMS_DBConnectionBean</ejb-link>
</ejb-ref>
</web-app>
Ejb jar is
<enterprise-beans>
<session>
<display-name>ConnectionBean</display-name>
<ejb-name>TMS_DBConnectionBean</ejb-name>
<home>tms.com.ejb.TMS_DBConnectionHome</home>
<remote>tms.com.ejb.TMS_DBConnection</remote>
<ejb-class>tms.com.ejb.TMS_DBConnectionBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<env-entry>
<env-entry-name>tmsDataSource</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>tmsPool</env-entry-value>
</env-entry>
<security-identity>
<description></description>
<use-caller-identity></use-caller-identity>
</security-identity>
<resource-ref>
<res-ref-name>tmsPool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<!--<res-sharing-scope>Shareable</res-sharing-scope>-->
</resource-ref>
</session>
</enterprise-beans>
<weblogic-ejb-jar>
weblogic ejb jar file is the following content.
<weblogic-enterprise-bean>
<ejb-name>TMS_DBConnectionBean</ejb-name>
<stateless-session-descriptor>
<pool>
<max-beans-in-free-pool>1</max-beans-in-free-pool>
</pool>
</stateless-session-descriptor>
<jndi-name>TMS_DBConnectionBean</jndi-name>
</weblogic-enterprise-bean>
thanx in advance..hi
i tried the same but still i'm getting the same problem, the value i mentioned in the servlet lookup is java:comp/env/TMS_DBConnectionBean.
then the value returned by the lookup would be java:comp/env/ejb/TMS_DBConnectionBean. right. Anyway i tried the same as u mentioned. that same problem resource not allowed is displayed in the browser. is there any other alternative to solve this?
thanks -
Servlet "files" doesn't recognize timeout ?
Hello folks,
I've encountered the following problem:
In the IFS I stored some documents in folders where only
privileged users can access to. The Webui displays the content
of folders als href-links, the link is the path to the document
inside the IFS. The problem is when I try to open the document
by clicking the link and the session was timeouted in the
meantime the Internet Explorer hangs up. I tried IE 5.0 and 5.5
with the same fault. Netscape 4.7 displays a dialog box and
requests user and password.
If I try to navigate in the Webui after a timeout I get an
timout message because every JSP checks the session at the
beginning.
Is this missing in the servlet "files" ?
I would expect a "timeout" oder "no access" message or page.
Any comments ?
Best regardsI guess it is a bug in the servlet IfsDavServlet.
I decompiled the class IfsDavServlet and had a look on the
source code.
Then there is no session available from the GET-request (i.e.
after a timeout), the servlet uses the guest user for accessing
the requested object in IFS. IMO the servlet should check
whether guest can access it and if not should respond an HTTP-
Error 501 instead of trying to read it.
Maybe you are looking for
-
Converting Acrobat 7 SDK -built plug-in to Acrobat 9
We have a plug-in developed inhouse with Acrobat 7 SDK. We are looking for someone with SDK programming experience to help us port it for Acrobat 9. We tried ourselves using Xcode compiler, but it seems that the plug-in is not showing up either as a
-
Ok... 100% honesty instead of making some story up; my boyfriend had an affair; mostly online. When I caught wind of this he mass cleared the whole internet history. This was at the end of august. I have found the places.sqlite file using the manager
-
Problem with 0HR_PA_1
Hi All, We are using 0HR_PA_1 to extract data for employee actions. We at present are using a full update mode with 'get yesterday'. There is no other restriction on the info package. We have observed taht the number of records reasching the PSA are
-
Hi, I try to design FIR filters with 501 coefficients (single symmetric coefficient set) an with max frequency > 650 MHz. Guess it should work because DSP48E1 max frequency is 740 MHz for 7-series -3 devices. Actually, it works fine if the number of
-
Changing the clip board size?
So I have this multipage document I am working on and I needed more pages so I added the artboards I need however then now go beyond the clip board size (see picture below), how do I change that?