简体   繁体   中英

JAVA JSP include JSP and response too

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM