开发者

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 creat开发者_Go百科e 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...


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.
}


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
      }
 }
%>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜