1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String reponame = req.getParameter("reponame");
if(reponame.compareTo("")==0){
returnError("Your text field was void !", req, resp, "createrep.jsp");
}
if(reponame.compareTo("/")==0){
returnError("You can not create a repertory named \'/\' !", req, resp, "createrep.jsp");
}
Pattern p = Pattern.compile("(\\/{0,1}\\w)*");
Matcher m = p.matcher(reponame);
if(!m.matches()){
returnError("Your path is not well written !", req, resp, "createrep.jsp");
}
String filepath = repos+reponame;
File newrep = new File(filepath);
if(!newrep.mkdir()){
returnError("Can not create your repertory !", req, resp, "createrep.jsp");
}
else{
returnMessage("Repertory created successfully", req, resp, "createrep.jsp");
}
}
public void returnError(String error, HttpServletRequest req, HttpServletResponse resp, String page) throws ServletException, IOException{
req.setAttribute("error", error);
RequestDispatcher rd = req.getRequestDispatcher(page);
rd.forward(req, resp);
}
public void returnMessage(String message, HttpServletRequest req, HttpServletResponse resp, String page) throws ServletException, IOException{
req.setAttribute("ok", message);
RequestDispatcher rd = req.getRequestDispatcher(page);
rd.forward(req, resp);
} |
Partager