Java Web应用开发

侯玉香,聂军,雷秦川,骆丽华,陈道敏,苗莹莹,刘叶

目录

  • 1 Java Web概述
    • 1.1 任务导引
    • 1.2 动态网页技术介绍
    • 1.3 JSP的运行环境
    • 1.4 JSP的运行原理
    • 1.5 JSP程序开发模式
    • 1.6 JSP开发工具
    • 1.7 任务实施:搭建项目环境及公司主页设计
    • 1.8 学习测验
  • 2 JSP基本语法
    • 2.1 任务导引
    • 2.2 JSP的基本组成
    • 2.3 脚本元素
    • 2.4 指令元素
    • 2.5 动作元素
    • 2.6 任务实施
    • 2.7 学习测验
  • 3 服务器交互
    • 3.1 任务导引
    • 3.2 课堂实录
    • 3.3 JSP内置对象概述
    • 3.4 out对象
    • 3.5 request对象
    • 3.6 response对象
    • 3.7 session对象
    • 3.8 application对象
    • 3.9 其他内置对象
    • 3.10 任务实施:使用JSP内置对象实现登录和注销功能
    • 3.11 学习测验
  • 4 JavaBean技术
    • 4.1 任务引导
    • 4.2 JavaBean概述
    • 4.3 JavaBean的应用
    • 4.4 JavaBean的作用域
    • 4.5 任务实施
    • 4.6 JSP中的文件操作
    • 4.7 学习测验
  • 5 Servlet技术
    • 5.1 任务引导
    • 5.2 Servlet基础
    • 5.3 Servlet开发
    • 5.4 Servlet常用API
    • 5.5 任务实施
    • 5.6 章节测验
  • 6 第6章 过滤器和监听器
    • 6.1 任务导引
    • 6.2 Servlet过滤器
    • 6.3 过滤器创建与配置
    • 6.4 Servlet监听器
    • 6.5 Servlet3.0新特性
    • 6.6 任务实施
    • 6.7 学习测验
  • 7 Java Web的数据库操作
    • 7.1 任务导引
    • 7.2 JDBC技术
    • 7.3 使用JDBC驱动程序访问数据库
    • 7.4 数据库连接的JavaBean
    • 7.5 JDBC对事务的操作
    • 7.6 连接池技术
    • 7.7 任务实施
    • 7.8 扩展阅读
    • 7.9 章节测验
  • 8 JSP高级技术
    • 8.1 任务导引
    • 8.2 EL概述
    • 8.3 JSTL标签库简介
    • 8.4 JSTL核心标签
    • 8.5 JSP与Ajax
    • 8.6 任务实施
    • 8.7 扩展阅读
    • 8.8 学习测验
  • 9 JSP实用组件技术
    • 9.1 任务导引
    • 9.2 上传与下载组件
    • 9.3 发送E-mail
    • 9.4 JSP动态图表
    • 9.5 在线编辑器
    • 9.6 任务实施
  • 10 教学过程材料
    • 10.1 2024-2025学年第一学期
      • 10.1.1 教学大纲
      • 10.1.2 授课计划
      • 10.1.3 实训指导书
      • 10.1.4 教案
      • 10.1.5 课件PPT
    • 10.2 2024-2025学年第二学期
      • 10.2.1 教学大纲
      • 10.2.2 授课计划
      • 10.2.3 实训指导书
      • 10.2.4 教案
      • 10.2.5 课件PPT
    • 10.3 2025-2026学年第一学期
      • 10.3.1 教学大纲
      • 10.3.2 授课计划
      • 10.3.3 实训指导书
      • 10.3.4 教案
      • 10.3.5 课件PPT
    • 10.4 2025-2026学年第二学期
      • 10.4.1 教学大纲
      • 10.4.2 授课计划
      • 10.4.3 实训指导书
      • 10.4.4 教案
      • 10.4.5 课件PPT
  • 11 课外资料
    • 11.1 电子书
      • 11.1.1 JavaWeb从入门到精通
      • 11.1.2 JavaWeb开发详解
      • 11.1.3 JavaWeb开发之道
      • 11.1.4 深入体验JavaWeb开发内幕-核心基础
      • 11.1.5 学通JavaWeb的24堂课
      • 11.1.6 Java Web 程序设计
      • 11.1.7 Java Web程序设计教程
      • 11.1.8 Java Web设计与应用教程
      • 11.1.9 Java_Web编程新手自学手册
      • 11.1.10 Tomcat and Java Web 开发技术详解
      • 11.1.11 Spring Boot 2+Thymeleaf企业应用实战
      • 11.1.12 Spring Boot+Vue全栈开发实战
      • 11.1.13 Spring实战
      • 11.1.14 JavaEE 8+Tomcat 9
    • 11.2 教学视频
      • 11.2.1 JDBC基础教学视频
      • 11.2.2 JDBC高级应用教学视频
任务实施:使用JSP内置对象实现登录和注销功能

请同学们先浏览PPT,这是一个任务点哈!完成后有惊喜哟!

任务实施:使用JSP内置对象实现登录和注销功能

login.jsp  、login_action.jsp处理登录页面、user.jsp、user.css、out.jsp退出登录页面共五个文件。

login.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <title>员工登录入口</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">

-->

<style type="text/css">

body{

width: 1100px;

text-align: center;

margin-left: auto;

margin-right: auto;

}

.div_01{

background-color: #cccccc;

border: 2px solid #aaaaaa;

width: 1100px;

height: 100px;

font-size: 20pt;

line-height: 100%;

}

</style>

  </head>

 

  <body>

     <div class="div_01">

      <h1>员工登录入口</h1>

     </div>

     <div class="div_02">

     <form action="${pageContext.request.contextPath}/LoginServlet3" method="post">

      <br/><br/><br/>

      用户名:<input type="text" name="userName"><br/><br/>

      密&nbsp;码:<input type="password" name="userPwd"><br/><br/>

      <input type="submit" value="登录">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

      <input type="reset" value="重置"><br>

      </form>

     </div>

  </body>

</html>

login_action.jsp处理登录界面。

<%@ page contentType="text/html;charset=UTF-8" %>

<html>

<head><title>登录处理</title></head>

<body>

处理页面

<%

String userName = request.getParameter("userName");

String userPwd = request.getParameter("userPwd");

if(userName==null||userPwd==null){

//request.setAttribute("message", "用户名或密码为空");

pageContext.forward("login.jsp");

}else if(userName.equals("lan") && userPwd.equals("123")){

session.setAttribute("userName", userName);

session.setAttribute("userPwd", userPwd);

pageContext.forward("user2.jsp");

//response.sendRedirect(request.getContextPath()+"/jsp/user2.jsp");

}else{

//request.setAttribute("message", "用户名或密码错误");

pageContext.forward("login.jsp");

}

%>

</body>

</html>

user.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <title>员工之窗</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="${pageContext.request.contextPath }/css/user.css">

<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>"+"/css/user.css">

  </head>

  <body>

 

     <div class="div_01">

      <h1>员工之窗</h1>

     </div>

     <div class="div_02">

      <span class="span_01"> <%= session.getAttribute("userName")%> </span>,欢迎你来到员工之窗。

      <br/>

      当前时间:<div id="span_02"  onclick="time()"></div>

     </div>

     <div class="div_03">

      <table border="1" cellspacing="0" align="center">

      <tr>

      <th id="th_01">文章编号</th>

      <th id="th_01">文章类型</th>

      <th id="th_01">标题</th>

      <th id="th_01">作者</th>

      <th id="th_01">发表日期</th>

      </tr>

      </table><br/>

      <a href="${pageContext.request.contextPath }/jsp/publish.jsp">【发表文章】</a>&nbsp;&nbsp;&nbsp;

      <a href="${pageContext.request.contextPath }/jsp/out.jsp">【退出登录】</a>&nbsp;&nbsp;&nbsp;

      <a href="${pageContext.request.contextPath }/index.jsp">【返回首页】</a>

     

     </div>

      <script type="text/javascript">

      function time2(){

var date = new Date();

          var time = (date.getFullYear()+"-"+(date.getMonth()+1)+"-"

          +date.getDate()+" "+date.getHours()+":"+

          date.getMinutes()+":"+date.getSeconds()); 

          document.getElementById("span_02").innerHTML = time;

      }

      window.setInterval(time2(), 1000);

</script>

  </body>

</html>

user.css

body{

width: 1100px;

text-align: center;

margin-left: auto;

margin-right: auto;

}

.div_01{

background-color: #cccccc;

border: 2px solid #aaaaaa;

width: 1100px;

height: 100px;

font-size: 20pt;

line-height: 100%;

}

.div_02{

text-align: left;

line-height: 20pt;

padding-top: 10px;

padding-bottom:10px;

font-weight: bold;

border-bottom: solid #777777 2px;

}

.div_03{

padding-top: 10px;

}

#th_01 {

background-color: #22ccff;

width: 140px;

height: 60px;

}

 a {

font-family: 宋体;

text-align: left;

text-decoration: underline;

TEXT-DECORATION: none;

}

.td_01{

text-align: center;

}

.span_01{

color:red;

}

.td_02{

text-align: center;

}


#span_02{

width: 250px;

height: 20px;

background-color: red;

}

out.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <title>注销登录</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>

    <%

    if(session.getAttribute("userName")!=null){

    session.invalidate();

    //out.print(1);

    response.sendRedirect("../index.jsp");

    }

    %>

  </body>

</html>