format()方法

使用inclue指令包含了一个date页面,在这个页面上显示了 被包含页面的内容。

新建date.jsp:

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%@ page import="java.text.*" %>
<%Date d=new Date();SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日");String s=sdf.format(d);out.println(s);
%>

新建Include_Command.jsp:

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body><h1>Include指令</h1><hr><%@ include file="date.jsp"%>
</body>
</html>

运行结果:

新建Include_Action,jsp:

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body><h1>Include指令</h1><hr><jsp:include page="date.jsp" flush="false"/>
</body>
</html>

包含页面的内容(源代码),并且和主页面转换为同一个servlet(类)。

主页面与包含页面是两个独立的类。

在这个类中并没有包含date.jsp的源代码,而是包含输出结果,相当于调用date.jsp,把它的输出结果打印输出。

等同于服务器内部跳转方法。

新建login.jsp:

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>My JSP 'login.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><h1>系统登录</h1><hr><form name="loginForm" action="Forward_Action.jsp" method="post"><table><tr><td>用户名:</td><td><input type="text" name="username"/></td></tr><tr><td>密码:</td><td><input type="password" name="password"/></td></tr><tr><td colspan="2"><input type="submit" value="登录"/></td></tr></table></form></body>
</html>

新建user.jsp:

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>My JSP 'user.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><h1>用户资料</h1><hr><%request.setCharacterEncoding("utf-8");String username="";String password="";if(request.getParameter("username")!=null){username=request.getParameter("username");}if(request.getParameter("password")!=null){password=request.getParameter("password");}%>用户名:<%=username %><br>密码:<%=password %><br></body>
</html>

新建Forward_Action.jsp:

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body><h1>Forward动作</h1><hr><jsp:forward page="user.jsp"/><%//相当于服务器内部跳转 %>
</body>
</html>

等价于服务器内部跳转方法:

Forward_Action.jsp:

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body><h1>Forward动作</h1><hr>
<%--     <jsp:forward page="user.jsp"/><%//相当于服务器内部跳转 %> --%><%request.getRequestDispatcher("user.jsp").forward(request,response);%>
</body>
</html>

结果效果一样。

给user.jsp传递了一个新的参数email:

新建dologin.jsp:

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body><jsp:forward page="user.jsp"><jsp:param value="admin@123.net" name="email"/></jsp:forward></body>
</html>

user.jsp:

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>My JSP 'user.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><h1>用户资料</h1><hr><%request.setCharacterEncoding("utf-8");String username="";String password="";String email="";if(request.getParameter("username")!=null){username=request.getParameter("username");}if(request.getParameter("password")!=null){password=request.getParameter("password");}if(request.getParameter("email")!=null){email=request.getParameter("email");}%>用户名:<%=username %><br>密码:<%=password %><br>电子邮箱:<%=email %><br></body>
</html>

login.jsp:

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>My JSP 'login.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><h1>系统登录</h1><hr><form name="loginForm" action="dologin.jsp" method="post"><table><tr><td>用户名:</td><td><input type="text" name="username"/></td></tr><tr><td>密码:</td><td><input type="password" name="password"/></td></tr><tr><td colspan="2"><input type="submit" value="登录"/></td></tr></table></form></body>
</html>

dologin.jsp:

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body><jsp:forward page="user.jsp"><jsp:param value="admin@123.net" name="email"/><jsp:param value="888888" name="password"/></jsp:forward></body>
</html>

观看慕课老师milanlover视频include指令+include动作+forward动作+param动作相关推荐

  1. 观看慕课老师milanlover视频Tomcat装在Servlet的三种情况+Servlet获取表单数据+Servlet相对路径

    在src新建TestServlet1: package servlet;import java.io.IOException; import java.io.PrintWriter;import ja ...

  2. 观看慕课老师milanlover视频用servlet获取初始化参数+MVC

    新建Index.jsp: <%@ page language="java" import="java.util.*" contentType=" ...

  3. 观看慕课老师milanlover视频Servlet+手工编写Servlet+用Eclipse编写Servlet+Servlet执行流程和生命周期

    eclipse 配置JDK HTML <a> 标签的 href 属性 新建MyFirstServletDemo项目: 新建index.jsp: <%@ page language=& ...

  4. 观看慕课老师milanlover视频JSP状态管理+cookie

    创建cookie对象调用它的构造方法,构造方法接收两个参数,是一种键值对描述:键:cookie对象的字符串描述:值:要保存的cookie对象. Value:字符串 The superclass &qu ...

  5. 观看慕课老师milanlover视频JavaBean+Jsp动作元素+page/request/session/application作用域范围+Model1

    Javabeans类写在src包里. 建一个实体类的po包,建一个用户类. 使用普通方式创建javabean实例: 新建Users.java: package com.po; /*用户类*/ publ ...

  6. 观看慕课老师milanlover视频JSP内置对象+getpost+request+response+请求转发与请求重定向

    out是内置对象,不用new来创建. 把饭盛到碗里,碗相当于程序中的缓冲区. <%@ page language="java" import="java.util. ...

  7. 观看慕课老师milanlover视频JSP页面生命周期+分别通过脚本和表达式实现九九乘法表

    但是多线程要注意临界资源的共享和保护问题. workplace地址: work地址: 新建项目: 插播一条编译错误: .java:说明有jsp编译生成的字节码文件. 大体上jsp页面的生命周期:Ini ...

  8. 观看慕课老师milanlover视频JSP基础语法+注释+脚本+声明+表达式

    JSP可理解为Java服务器端页面:是一种动态网站开发技术的标准,同时也是JavaEE的参考标准. v <%@ page language="java" import=&qu ...

  9. Makefile的重建与include指令

    Makefile的重建与include指令 include指令 当make看到include指令时,会事先对通配符以及变量引用进行扩展,然后试着读引入文件(include file). 如果这个文件存 ...

最新文章

  1. android jni语法,Android NDK中的JNIEXPORT和JNICALL
  2. 下一个全球电子通道系统,一定是BCH!
  3. Pwnium CTF2014 – MatterOfCombination writeup
  4. 设计时数据源:在PostgreSql 数据查询中使用参数过滤
  5. C指针原理(26)-gtk
  6. SpringMVC实现文件的上传与下载
  7. 为C# Windows服务添加安装程序
  8. 【流媒体FLV封装协议】
  9. PIL简单图片处理(上)
  10. SQL Server索引视图以(物化视图)及索引视图与查询重写
  11. 【Luogu2394】yyy loves Chemistry I(浮点数精度)
  12. Hbase数据模型入门
  13. Linux RedHat 7 配置本地 YUM源
  14. 【MATLAB】进阶绘图 ( Stairs 阶梯图 | stairs 函数 | Stem 离散序列数据图 | stem 函数 | 正弦函数采样 )
  15. 关于网络拓扑图,你想知道的都在这
  16. DOS操作系统基本使用方法
  17. [并发并行]_[线程池]_[Programming With POSIX Threads的线程池实现分析1]
  18. 基于OpenCV自带分类器识别人脸
  19. ubuntu下常用软件下载安装
  20. Service Mesh介绍

热门文章

  1. java 修改pdf图片_java代码将pdf 转换成图片加缩略图 -3
  2. 《东邪西毒》(Ashes of Time)
  3. python中执行shell脚本之subprocess模块,python用subprocess执行shell脚本
  4. CTF中pwn的入门指南
  5. 女博士的生活是怎么样的?
  6. Prolog教程 1
  7. python颜色代码棕色_python – 根据轮廓颜色着色
  8. 转:49个瓶子你选哪个?
  9. 如何把家装修出温馨的感觉?极家好不好
  10. 微信小游戏---HTML学习笔记(1)