Pass variable from the daughter page to the parent page in jsp

1

I am making a simple crud in java using jsp and servlets . And I came across the following situation:

I have layout.jsp which makes the include of another dynamic page, which in this case will be excluir.jsp . The page title is set within excluir.jsp so the layout.jsp page does not see the value of my title variable.

I ask: how can layout.jsp get the value of title .

Note: I'm trying hard not to put this information in servlet . Yes I know that if this variable is set to servlet the layout .jsp can get the value.

  

layout.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt"       prefix="c"   %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"       prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml"       prefix="x"   %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql"       prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"  %>
<!doctype html>
<html lang="pt-BR">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><c:out value="${title}" /></title>
    <link href="/css/bootstrap.min.css" rel="stylesheet" />
    <link href="/css/theme.css" rel="stylesheet" />
</head>
<body>
<c:import url="menu.jsp" />
<div class="container">
    <c:import url = "${page}" />
</div>
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
</body>
</html>
  

delete.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt"       prefix="c"   %>
<c:set var="title" scope="request" value="Excluir página"/>
<h1><c:out value="${title}" /></h1>
    
asked by anonymous 22.02.2017 / 19:09

1 answer

1

Declare your c:import as a variable somewhere before you are using the title attribute. Example:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt"       prefix="c"   %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"       prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml"       prefix="x"   %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql"       prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"  %>

<c:import var = "importedPage" url = "${page}" />   <%-- Aqui você declara seu import --%>

<!doctype html>
<html lang="pt-BR">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><c:out value="${title}" /></title>
    <link href="/css/bootstrap.min.css" rel="stylesheet" />
    <link href="/css/theme.css" rel="stylesheet" />
</head>
<body>
<c:import url="menu.jsp" />
<div class="container">
    ${importedPage}                                 <%-- Aqui você usa seu  import --%>
</div>
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
</body>
</html>
    
22.02.2017 / 20:29