Commit ebb21f89 by Billy Larru

modificando js para usar jsp dentro de directorios

parent 219df09c
///*
// * To change this license header, choose License Headers in Project Properties.
// * To change this template file, choose Tools | Templates
// * and open the template in the editor.
// */
//package asistencia.filters;
//
//import java.io.IOException;
//import java.io.PrintStream;
//import java.io.PrintWriter;
//import java.io.StringWriter;
//import java.util.ArrayList;
//import java.util.List;
//import javax.servlet.Filter;
//import javax.servlet.FilterChain;
//import javax.servlet.FilterConfig;
//import javax.servlet.ServletException;
//import javax.servlet.ServletRequest;
//import javax.servlet.ServletResponse;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.http.Cookie;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpSession;
//import javax.ws.rs.WebApplicationException;
//import javax.ws.rs.core.Response;
//import org.json.JSONArray;
//import org.json.JSONObject;
//import asistencia.config.RequestPath;
//import asistencia.utilities.GeneralUtils;
//import asistencia.utilities.HttpRequest;
//
///**
// *
// * @author sistem08user
// */
//@WebFilter(filterName = "RequestFilter", urlPatterns = {"/*"})
//public class RequestFilter implements Filter {
//
// // The filter configuration object we are associated with. If
// // this value is null, this filter instance is not currently
// // configured.
// private FilterConfig filterConfig = null;
//
// public RequestFilter() {
// }
//
// private void doBeforeProcessing(ServletRequest req, ServletResponse resp, FilterChain chain)
// throws IOException, ServletException {
// HttpServletRequest request = (HttpServletRequest) req;
// HttpServletResponse response = (HttpServletResponse) resp;
// String uri = request.getRequestURI();
//
// if (uri.endsWith("Asistencia") || uri.endsWith("Asistencia/")
// || uri.contains("vistas/index.jsp")
// || uri.contains("plantilla/assets") || uri.endsWith(".js") || uri.endsWith(".css")
// || uri.endsWith(".png") || uri.endsWith(".jpg") || uri.endsWith(".gif")
// || uri.contains("/login") || uri.contains("vistas/redireccionarServlet")
// || uri.contains("vistas/interceptar")) {
// chain.doFilter(request, response);
// } else {
// if (request.getSession().getAttribute("codigo") != null) {
// if (uri.endsWith(".jsp")) {
// HttpSession session = request.getSession();
// HttpRequest httpRequest = new HttpRequest();
// JSONObject valid = null;
// String respuesta = "";
// String auth = "";
// try {
// if (session.getAttribute("Authorization") != null) {
// auth = (String) session.getAttribute("Authorization");
// } else {
// setError(response);
// }
// respuesta = httpRequest.getRespuesta(RequestPath.VERIFICAR_LOGIN, HttpRequest.POST, new JSONObject("{}"), auth);
// valid = new JSONObject(respuesta);
// if (valid.getBoolean("status")) {
// JSONObject menu = new JSONObject(valid.getString("menu"));//Obtiene el menu
// List<Object> vistas = new ArrayList<>();
// JSONObject rolvista = valid.getJSONObject("rolvista");
// JSONArray urls = rolvista.getJSONArray("vistas");
// for (int i = 0; i < urls.length(); i++) {
// vistas.add(urls.get(i));
// }
// vistas.add("main.jsp");
// String ruta = request.getRequestURI();
// int indice = GeneralUtils.obtenerIndex(ruta);
// String rutaJsp = ruta.substring(indice, ruta.length());
// boolean acceso = vistas.contains(rutaJsp);
// if (!acceso) {
// request.getSession().setAttribute("error", "no tiene acceso a la vista solicitada");//Esta session se elimina en el jsp (para que no ocupe memoria)
//// request.getRequestDispatcher("/vistas/error.jsp").forward(request, response);
// response.sendRedirect("error/error.jsp");
// return;
// }
// session.setAttribute("menu", menu.toString());
// } else {
// deleteCredenciales(response, request);
// request.getSession().setAttribute("error", "no tiene credenciales validas");
//// request.getRequestDispatcher("/vistas/error.jsp").forward(request, response);
// response.sendRedirect("error/error.jsp");
// return;
//// setError(response);
// }
// } catch (Exception ex) {
// request.getSession().setAttribute("error", ex.getMessage());
//// request.getRequestDispatcher("/vistas/error.jsp").forward(request, response);
// response.sendRedirect("error/error.jsp");
// return;
//// setError(response);
// }
// }
// chain.doFilter(request, response);
// } else {
// deleteCredenciales(response, request);
// response.sendRedirect("index.jsp");
// }
// }
// }
//
// private void deleteCredenciales(HttpServletResponse response, HttpServletRequest request) {
// Cookie cookieAuth = new Cookie("Authorization", "");
// cookieAuth.setMaxAge(0);
// request.getSession().invalidate();
// response.addCookie(cookieAuth);
// }
//
// private void sendError(HttpServletResponse response) throws IOException {
// response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
// response.sendError(401);
// }
//
// public void setError(HttpServletResponse response) throws IOException {
// Response.ResponseBuilder builder = null;
// sendError(response);
// builder = Response.status(Response.Status.UNAUTHORIZED).entity(response);
// throw new WebApplicationException(builder.build());
// }
//
// private void doAfterProcessing(ServletRequest request, ServletResponse response)
// throws IOException, ServletException {
//
// }
//
// public void doFilter(ServletRequest req, ServletResponse resp,
// FilterChain chain)
// throws IOException, ServletException {
// System.out.println("Entrando al filtro");
// doBeforeProcessing(req, resp, chain);
//
//// chain.doFilter(req, resp);
// doAfterProcessing(req, resp);
//
// }
//
// /**
// * Return the filter configuration object for this filter.
// */
// public FilterConfig getFilterConfig() {
// return (this.filterConfig);
// }
//
// /**
// * Set the filter configuration object for this filter.
// *
// * @param filterConfig The filter configuration object
// */
// public void setFilterConfig(FilterConfig filterConfig) {
// this.filterConfig = filterConfig;
// }
//
// /**
// * Destroy method for this filter
// */
// public void destroy() {
// }
//
// /**
// * Init method for this filter
// */
// public void init(FilterConfig filterConfig) {
//
// }
//
// private void sendProcessingError(Throwable t, ServletResponse response) {
// String stackTrace = getStackTrace(t);
//
// if (stackTrace != null && !stackTrace.equals("")) {
// try {
// response.setContentType("text/html");
// PrintStream ps = new PrintStream(response.getOutputStream());
// PrintWriter pw = new PrintWriter(ps);
// pw.print("<html>\n<head>\n<title>Error</title>\n</head>\n<body>\n"); //NOI18N
//
// // PENDING! Localize this for next official release
// pw.print("<h1>The resource did not process correctly</h1>\n<pre>\n");
// pw.print(stackTrace);
// pw.print("</pre></body>\n</html>"); //NOI18N
// pw.close();
// ps.close();
// response.getOutputStream().close();
// } catch (Exception ex) {
// }
// } else {
// try {
// PrintStream ps = new PrintStream(response.getOutputStream());
// t.printStackTrace(ps);
// ps.close();
// response.getOutputStream().close();
// } catch (Exception ex) {
// }
// }
// }
//
// public static String getStackTrace(Throwable t) {
// String stackTrace = null;
// try {
// StringWriter sw = new StringWriter();
// PrintWriter pw = new PrintWriter(sw);
// t.printStackTrace(pw);
// pw.close();
// sw.close();
// stackTrace = sw.getBuffer().toString();
// } catch (Exception ex) {
// }
// return stackTrace;
// }
//
// public void log(String msg) {
// filterConfig.getServletContext().log(msg);
// }
//
//}
......@@ -47,7 +47,7 @@ public class RequestsFilter implements Filter {
String uri = request.getRequestURI();
if (uri.endsWith("vistas/index.jsp")) {
if (request.getSession().getAttribute("codigo") != null) {
response.sendRedirect("main.jsp");
response.sendRedirect(request.getContextPath() + "/vistas/main.jsp");
return;
}
chain.doFilter(req, resp);
......@@ -75,31 +75,30 @@ public class RequestsFilter implements Filter {
for (int i = 0; i < urls.length(); i++) {
vistas.add(urls.get(i));
}
vistas.add("main.jsp");
String ruta = request.getRequestURI();
// int indice = GeneralUtils.obtenerIndex(ruta);
// String rutaJsp = ruta.substring(indice, ruta.length());
String rutaJsp = GeneralUtils.obtenerURIvista(ruta);
System.out.println("Ruta: "+ruta);
System.out.println("rutajsp: "+rutaJsp);
System.out.println("Ruta: " + ruta);
System.out.println("rutajsp: " + rutaJsp);
System.out.println(vistas);
boolean acceso = vistas.contains(rutaJsp);
System.out.println(acceso);
if (!acceso) {
request.getSession().setAttribute("error", "no tiene acceso a la vista solicitada");//Esta session se elimina en el jsp (para que no ocupe memoria)
request.getRequestDispatcher("/vistas/error.jsp").forward(request, response);
request.getRequestDispatcher(request.getContextPath() + "/vistas/error.jsp").forward(request, response);
return;
}
session.setAttribute("menu", menu.toString());
} else {
deleteCredenciales(response, request);
request.getSession().setAttribute("error", "no tiene credenciales validas");
request.getRequestDispatcher("/vistas/error.jsp").forward(request, response);
request.getRequestDispatcher(request.getContextPath() + "/vistas/error.jsp").forward(request, response);
return;
}
} catch (Exception ex) {
request.getSession().setAttribute("error", ex.getMessage());
request.getRequestDispatcher("/vistas/error.jsp").forward(request, response);
request.getRequestDispatcher(request.getContextPath() + "/vistas/error.jsp").forward(request, response);
return;
}
}
......@@ -107,7 +106,7 @@ public class RequestsFilter implements Filter {
} else {
deleteCredenciales(response, request);
request.getSession().setAttribute("error", "no tiene una sesion activa");
request.getRequestDispatcher("/vistas/error.jsp").forward(request, response);
request.getRequestDispatcher(request.getContextPath() + "/vistas/error.jsp").forward(request, response);
}
}
}
......
......@@ -37,7 +37,6 @@ public class GeneralUtils {
if (matcher.find()) {
rutaVista = matcher.group(1);
}
System.out.println(rutaVista);
return rutaVista;
}
}
......@@ -6,8 +6,9 @@ const DOMSideBar = {
},
setMenu() {
let location = window.location;
let position = getUrl(location.pathname, "/");
let path = location.pathname.substring(position + 1);//obtiene el nombre de la vista jsp para activar la clase .active
// let position = getUrl(location.pathname, "/");
// let path = location.pathname.substring(position + 1);//obtiene el nombre de la vista jsp para activar la clase .active
let path = getUrl(location.href);
let menu = document.getElementById("MENU");
let c = window.sidebar;//obtiene el menu
console.log(c)
......@@ -15,6 +16,7 @@ const DOMSideBar = {
let html = "";
let active = "";
/* Recorrer titulos */
debugger;
for (var i in contenido) {
let titulo = contenido[i].titulo;
html += `<li class="navigation-header"><span><i class="fa ${titulo.ico} fa-lg" title="Main pages"></i> ${titulo.nombre}</span></li>`;
......@@ -43,7 +45,7 @@ const DOMSideBar = {
} else {
active = '';
}
html += `<li class="${active}"><a href="${subcategoria[l].url}"><span>${primeraLetraMayuscula(subcategoria[l].nombre)}</span></a></li>`;
html += `<li class="${active}"><a href="${contextPath}vistas/${subcategoria[l].url}"><span>${primeraLetraMayuscula(subcategoria[l].nombre)}</span></a></li>`;
}
html += `</li></ul>`;
} else {
......@@ -68,15 +70,21 @@ const DOMSideBar = {
logOut();
}
}
let getUrl = (pathname, caracter) => {
let position = 0;
for (let i = pathname.length - 1; i > 0; i--) {
if (pathname[i] === caracter) {
position = i;
break;
}
}
return position;
//let getUrl = (pathname, caracter) => {
// let position = 0;
// for (let i = pathname.length - 1; i > 0; i--) {
// if (pathname[i] === caracter) {
// position = i;
// break;
// }
// }
// return position;
//}
let getUrl = path => {
let pattern = "^(?:.*)/vistas/(.*)$";
let match = path.match(pattern);
return match[1];
}
DOMSideBar.init();
\ No newline at end of file
<jsp:include page="/vistas/templates/validar.jsp" />
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="/vistas/templates/header.jsp" />
<!--template-core-->
<!--css de la pagina-->
<!--css-->
</head>
<body>
<jsp:include page="/vistas/templates/header-body.jsp" />
<!-- content -->
<!-- / content -->
<jsp:include page="/vistas/templates/footer-body.jsp" />
<!--js de la pagina-->
<!--<script src="${pageContext.request.contextPath}/plantilla/assets/js/plugins/tables/datatables/datatables.min.js" type="text/javascript"></script>-->
<!--js-->
</body>
</html>
\ No newline at end of file
<jsp:include page="/vistas/templates/validar.jsp" />
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="/vistas/templates/header.jsp" />
<!--template-core-->
<!--css de la pagina-->
<!--css-->
</head>
<body>
<jsp:include page="/vistas/templates/header-body.jsp" />
<!-- content -->
<!-- / content -->
<jsp:include page="/vistas/templates/footer-body.jsp" />
<!--js de la pagina-->
<!--<script src="${pageContext.request.contextPath}/plantilla/assets/js/plugins/tables/datatables/datatables.min.js" type="text/javascript"></script>-->
<!--js-->
</body>
</html>
\ No newline at end of file
<jsp:include page="/vistas/templates/validar.jsp" />
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="/vistas/templates/header.jsp" />
<!--template-core-->
<!--css de la pagina-->
<!--css-->
</head>
<body>
<jsp:include page="/vistas/templates/header-body.jsp" />
<!-- content -->
<!-- / content -->
<jsp:include page="/vistas/templates/footer-body.jsp" />
<!--js de la pagina-->
<!--<script src="${pageContext.request.contextPath}/plantilla/assets/js/plugins/tables/datatables/datatables.min.js" type="text/javascript"></script>-->
<!--js-->
</body>
</html>
\ No newline at end of file
<jsp:include page="/vistas/templates/validar.jsp" />
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="/vistas/templates/header.jsp" />
<!--template-core-->
<!--css de la pagina-->
<!--css-->
</head>
<body>
<jsp:include page="/vistas/templates/header-body.jsp" />
<!-- content -->
<!-- / content -->
<jsp:include page="/vistas/templates/footer-body.jsp" />
<!--js de la pagina-->
<!--<script src="${pageContext.request.contextPath}/plantilla/assets/js/plugins/tables/datatables/datatables.min.js" type="text/javascript"></script>-->
<!--js-->
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment