This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Servlets and the fly likes Creating File object in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Creating File object in servlet" Watch "Creating File object in servlet" New topic
Author

Creating File object in servlet

Servin Park
Greenhorn

Joined: May 10, 2002
Posts: 26
Hello,
I am building a webapp using MVC pattern, servlet as controller, jsp as view and javaBeans as model.
My webapp will let editors to modify or add new columns or essays as they please. My plan is to create or modify existing
html file with their writings and just include( <jsp:include ...> ) those files in jsp. However, I am having
trouble writing files in servlet. For instance, following code
...
File temp = new File("\column.html");
temp.createNewFile();
...
creates column.html in C:\column.html. what I what is to be able to create html files in the same level as WEB-INF directory and let jsp include them with no problem. Many thanks in advance for your help
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60080
    
  65

Check out the ServletContext.getRealPath() method. With it you can determine the absolute file path to a location given any relative path. For example, feed it "/" to determine the root of your web application.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating File object in servlet
 
Similar Threads
Resolving a URL in include action tag?
File downloading from directory external to webapp
overriding jspInit() problem
Elementary Jsp Include Question
servlet to JSP to HTML to JSP