Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating File object in servlet

 
Servin Park
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic