Java/JSP/Include

Материал из Java эксперт
Перейти к: навигация, поиск

Forward a request

   <source lang="java">

// getrequest.jsp anything here will now appear in the browser <jsp:forward page="gotForwardedRequest.jsp"/> anything here will not appear //File: gotForwardedRequest.jsp <html> <head><title>Request forwarded here</title></head> <body> This page received a forwarded request from getRequest.jsp,
This page is the output from gotForwardedRequest.jsp,
but the URL is for getRequest.jsp. </body> </html>


      </source>
   
  
 
  



Include another file

   <source lang="java">

<html>

 <HEAD><TITLE>Include another file</TITLE></HEAD>
 <BODY>
   <%@ include file="welcomeText.html" %>

This text appears after the included file </BODY> </HTML> // File:welcomeText.html

Welcome to your online account


      </source>
   
  
 
  



JSP Include

   <source lang="java">

//File: index.html <%@ page errorPage="errorpage.jsp" %> <html>

 <head>
   <title>Welcome to JSP</title>
 </head>
 <body>
         <%@ include file="titlebar.jsp" %>
       <%
out.println("
This is the client area.
");
       %>
 </body>

</html>

////////////////////////////////////////////////////////////// //File: titleBar.jsp

     <%
       // Get the User"s Name from the session
       out.println("Hello: " + request.getParameter("user") + "");
     %>


      </source>
   
  
 
  



Jsp Include Static HTML

   <source lang="java">

//File: includeTest.jsp <HTML> <HEAD><TITLE> Include Test </TITLE></HEAD> <BODY> I should see this
<%@ include file="insert.html" %>

If I don"t, then the URL is not working... </BODY> </HTML> ///////////////////////////////////////////// //File: insert.html right below the line that reads: "I should see this"

      </source>
   
  
 
  



Jsp page includes another Jsp page

   <source lang="java">

//File: index.jsp <html>

<body bgcolor="white"> <%@ page buffer="5kb" autoFlush="false" %> <p>In place evaluation of another JSP which gives you the current time: <%@ include file="foo.jsp" %> <p> <jsp:include page="foo.html" flush="true"/> by including the output of another JSP: <jsp:include page="foo.jsp" flush="true"/>

-)

</html>

//////////////////////////////////////////////////////////////////// //File: foo.jsp

<body bgcolor="white"> <%= System.currentTimeMillis() %> //////////////////////////////////////////////////////////////////// //File: foo.html

To get the current time in ms


      </source>
   
  
 
  



JSP standard action: include

   <source lang="java">

/* Beginning JavaServer Pages Vivek Chopra, Jon Eaves, Rupert Jones, Sing Li, John T. Bell ISBN: 0-7645-7485-X

  • /


      </source>
   
  
 
  



Passing parameters during including

   <source lang="java">

<html> <head> <title>This page passes parameters</title> </head> <body>

<jsp:include page="includeFileNeedingAParameter.jsp">

 <jsp:param name="department" value="Electrical"/>

</jsp:include> Above text is from includeFileNeedingAParameter.jsp. </body> </html> //File : includeFileNeedingAParameter.jsp

<%=request.getParameter("department") %> Department


      </source>
   
  
 
  



Using Include And Pass Value

   <source lang="java">

//File: index.jsp <%@ page errorPage="errorpage.jsp" %> <html>

 <head>
   <title>Employee Information</title>
 </head>
 <body>
</body> </html> /////////////////////////////////////////////////////////////// //File: header.jsp <% out.println("Employee: " + request.getParameter("employee")); out.println("
Title: " + request.getParameter("title")); %> </source>

Using Includes

   <source lang="java">

<html> <head> <title>Using Includes</title> </head> <body>

<jsp:include page="tableheader.html" flush="true"/>

<jsp:include page="maincontent.jsp" flush="true"/>

<jsp:include page="tablefooter.html" flush="true"/> </body> </html>


      </source>
   
  
         <jsp:include page="header.jsp" flush="true">
           <jsp:param name="employee" value="Bob"/>
           <jsp:param name="title" value="Engineer"/>
         </jsp:include>