Learner
Learner

Reputation: 345

Dynamic Folder Creation

i want to make absolute path for register users

for example website url is www.icare.com

when a user register himself with user name like "Myname" a dynamic folder will create and

absolute path for that user will be like www.icare.come/Myname. . . and a dummy index page

will create, any one can help me...

Upvotes: 0

Views: 2620

Answers (2)

BalusC
BalusC

Reputation: 1108632

Don't create folders on web root. They will all get lost whenever you redeploy the webapp.

Just store all data in a DB, create a common JSP file for all users which displays the data from the DB dynamically, create a servlet which is mapped on /* and does roughly the following job:

String username = request.getPathInfo().substring(1);
User user = userDAO.find(username);

if (user != null) {
   request.setAttribute("user", user);
   request.getRequestDispatcher("/WEB-INF/userindex.jsp").forward(request, response);
} else {
   // Show "unknown user" error page or whatever.
}

Upvotes: 1

Developer
Developer

Reputation: 8636

Try this

<%@ page import="java.io.*,java.io.File" %>
<%
 File dir = new File("Your Path to create directory");
 if (dir.exists()) 
   {
      if (dir.isDirectory()) {
           // path exists and is a directory
    }
      else {
           // path does exist but is not a directory -- probably just a file
      }
 }
 else {
      // path does not exist so create directory
      if (dir.mkdir()) {
           // directory creation successful
      }
      else {
           // directory creation unsuccessful
      }
 }
%>

Upvotes: 1

Related Questions