Jsp 8—— 动作
a.jsp(include)
<%@page contentType="text/html; charset=UTF-8"%>
<html>
<head>
<title>include动作</title>
</head>
<body>
<%--
关于JSP中的include动作:
1、a.jsp包含b.jsp,底层会分别生成两个java源文件,两个class字节码文件
2、编译阶段并没有包含,编译阶段是两个独立的class字节码文件,生成两个Servlet,两个独立的service方法
3、使用include动作属于运行阶段包含, 实际上是在运行阶段a中的service方法调用了b中的service方法,达到了包含效果
4、a.jsp包含b.jsp,若两个jsp文件中有重名的变量,只能使用动态包含。其余都可以使用静态包含。
5、include动作完成的动态包含,被称为动态联编。
--%>
<jsp:include page="/b.jsp"></jsp:include>
</body>
</html>
b.jsp
<h1 align="center"><font color="red">include...</font></h1>

index.jsp(forword)
<%@page contentType="text/html; charset=UTF-8"%> <%-- 关于JSP中的动作: 语法格式:<jsp:动作名 属性名=属性值 属性名=属性值....></jsp:动作名> --%> <% request.setAttribute("username","wangwu"); %> <%-- 转发是一次请求 --%> <%-- <jsp:forward page="/index2.jsp"></jsp:forward> --%> <%-- 以上JSP的动作可以编写为对应的java程序进行实现 --%> <%-- <% request.getRequestDispatcher("/index2.jsp").forward(request,response); %> --%> <%-- 编写java程序完成重定向 --%> <% response.sendRedirect(request.getContextPath() + "/index2.jsp"); %> <%-- JSP主要是完成页面的展示,最好在JSP文件中少的编写java源代码: 以后会通过EL表达式 + JSTL标签库来代替JSP中的java源代码 当然,使用某些动作也能代替java源代码 --%>
index2.jsp
<%@page contentType="text/html; charset=UTF-8"%>
<%=request.getAttribute("username") %>

bean.jsp(bean)
<%@page contentType="text/html; charset=UTF-8"%> <%-- JSP中的bean动作: * useBean * setProperty * getProperty 以上的bean动作使用较少,作为了解。 --%> <%-- <jsp:useBean id=""></jsp:useBean> <jsp:setProperty property="" name=""/> <jsp:getProperty property="" name=""/> --%>
转载请注明出处:https://www.cnblogs.com/stu-jyj3621

浙公网安备 33010602011771号