0

I would like to include an jsp and (separate) response with it too.

include:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <div><%@include file="content.jsp" %></div>
    </body>
</html>

and this is content.jsp:

<p>${message}</p>

Message is a text from database. eg.: "Hello!"

Responses: url: /

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <div>Hello!</div>
    </body>
</html>

url: /hello

<p>Hello!</p>

So my ask is how I recycle a jsp file if it is contain parameters?

Gábor Varga
  • 840
  • 5
  • 15
  • 25

1 Answers1

0

So my ask is how I recycle a jsp file if it is contain parameters?

  1. Using an efficient template system, fragmenting your jsp and create pages with single include.

  2. Or you use

       <%  
          String message1 = request.getParameter("message");  
       %>
    
       <jsp:include page="...." >
          <jsp:param name="param1" value=<%=message1%> >
          </jsp:param>  
       </jsp:include>
    
  3. Or you can copy and paste and using controller to manage the parameters.

Giorgio Desideri
  • 169
  • 1
  • 12