second.jsp:
<%@ page session="true" %> <html> <body> <% String str = request.getParameter("first_name");%> Your name is <h4><%= str%></h4> <% session.setAttribute("name", str);%> <form action="Third.jsp"><br> Send the request to next page<br> <input type="submit" value="Send"> </form> </body> </html>
Copyright.html:
<html> <br> <br> <br> All copy rights are reserved for onitroad </html>
开发将参加会话的JSP页面
Include指令:
Include包括服务器副资源的指令。
服务器端资源可以是HTML文件或者JSP或者Servlet。
如果我们包含HTML文件,则在响应呈现给客户端时将由浏览器执行。
当我们包含JSP或者Servlet时,它将被容器执行。
语法:
<% include file = "file name to be included" %>
例如:
<% include file = "copyright.html" %>
Exception.jsp:
<%@ page isErrorPage="false" errorPage="ErrorPage.jsp" %> <html> <body> <%= 30/0%> </body> </html>
示例
first.jsp:
<%@ page session="true" %> <html> <body> <form name="first" action="Second.jsp"> Enter your name : <input type="text" name="first_name"><br> <input type="submit" value="Send"> </form> </body> </html>
Third.jsp:
<%@ page session="true" %> <html> <body> Value in third page from session objects is <h4><%= session.getAttribute("name")%></h4> </body> </html>
errorpage.jsp:
<%@ page isErrorPage="true" %> <html> <body> Exception is <%= exception%> generated...<br> Exception message is <%= exception.getMessage()%><br> <%@ include file="copyright.html" %> </body> </html>
JSP指令:
指令基本上用于配置Servlet中容器生成的代码。
作为JSP的一部分,我们有三种类型的指令;它们是页面指令,包括指令和Taglib指令。
web.xml:
<web-app> </web-app>
web.xml:
<web-app> </web-app>
JSP页面指令:
页面指令基本上用于将编译时间信息提供给用于生成servlet的容器。
页面指令将以(键,值)对的形式获取数据。
<%@ page attribute_name1=attribute_value1, attribute_name2=attribute_value2, ...................................., Attribute_nameN=attribute_valueN %>
- 每当我们使用页面指令作为JSP程序的一部分,该语句必须是第一个语句。
- 页面指令的范围仅适用于当前的JSP页面。
日期:2020-04-11 23:04:38 来源:oir作者:oir