Common processing and error processing
Reference URL
https://www.techscore.com/tech/Java/JavaEE/Servlet/6/
Explanation By implementing the implements Filter, common processing can be created.
Later, when it is completely finished. When it is completely finished.
@Override
public void destroy() {
System.out.println("destroy");
}
When loaded for the very first time
@Override
public void init(FilterConfig filterConfig) throws ServletException {
System.out.println("init");
}
★ Every time the controller is called
//Is it a direct URL?
/* if(req.getHeader("referer") == null&&!req.getRequestURI().equals("/OfficeSystem_Hibernate/Login")){
//Does the URL path exist in Request Mapping
if(list.contains(req.getServletPath())) {
throw new Exception("BACKLOGIN");
}else {
//System.out.println(req.getServletPath()+"Shows error page because does not exist");
throw new Exception("NotFoundError");
}
}
if(req.getRequestURI().equals("/OfficeSystem_Hibernate/SendMail")) { //Fix
if(session.getAttribute("role").toString().equals("0")) { //Fix
throw new Exception("No access rights"); //Fix
} //Fix
} //Fix
}else if(ex.getMessage().equals("No access rights")) { //Fix
request.setAttribute("errmessage", ex); //Fix
req.getRequestDispatcher("/WEB-INF/error/InternalError.jsp") //Fix
.forward(req, res); //Correction transfer
}
Recommended Posts