JavaWeb_07-01-el-jstl-release

JavaWeb_07-01-el-jstl-release

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

City

package xyc.sjxy.pojo;

public class City {
    private String cId;
    private String cName;

    //private Province province;

    public City() {

    }

    public City(String cId, String cName) {
        this.cId = cId;
        this.cName = cName;
    }

    public String getcId() {
        return cId;
    }

    public void setcId(String cId) {
        this.cId = cId;
    }

    public String getcName() {
        return cName;
    }

    public void setcName(String cName) {
        this.cName = cName;
    }

    @Override
    public String toString() {
        return "City{" +
                "cId='" + cId + '\'' +
                ", cName='" + cName + '\'' +
                '}';
    }
}

LoginInfo

package xyc.sjxy.pojo;

public class LoginInfo {
    private String loginId;
    private  String loginPwd;
    private  String loginName;

    public String getLoginId() {
        return loginId;
    }

    public void setLoginId(String loginId) {
        this.loginId = loginId;
    }

    public String getLoginPwd() {
        return loginPwd;
    }

    public void setLoginPwd(String loginPwd) {
        this.loginPwd = loginPwd;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    @Override
    public String toString() {
        return "LoginInfo{" +
                "loginId='" + loginId + '\'' +
                ", loginPwd='" + loginPwd + '\'' +
                ", loginName='" + loginName + '\'' +
                '}';
    }
}

Users

package xyc.sjxy.pojo;

/**
 * javaBean 实际上 就是一个普通的java类--》pojo
 */
public class Users {
    private long id;
    private String name;
    private String pwd;
    private boolean sex;
    private int age;
    private String hobby;

    private City city;

    public Users() {
    }

    public Users(long id, String name, String pwd, boolean sex, int age) {
        this.id = id;
        this.name = name;
        this.pwd = pwd;
        this.sex = sex;
        this.age = age;
    }

    /*public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }*/

    public City getCity() {
        return city;
    }

    public void setCity(City city) {
        this.city = city;
    }

    public String getHobby() {
        return hobby;
    }

    public void setHobby(String hobby) {
        this.hobby = hobby;
    }

    public long getId1() {  //属性id1的get访问器
        return id;
    }

    public void setId1(long id) { //属性id1的set访问器
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public boolean isSex() {   //属性sex的get访问器,只是访问器名称叫is
        return sex;
    }

    public void setSex(boolean sex) { //属性sex的set访问器
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Users{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", pwd='" + pwd + '\'' +
                ", sex=" + sex +
                ", age=" + age +
                ", hobby='" + hobby + '\'' +
                ", city=" + city +
                '}';
    }
}

Bean

package xyc.sjxy.servlet;

import org.apache.commons.beanutils.BeanUtils;
import xyc.sjxy.pojo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@WebServlet("/bean")
public class Bean  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       req.setCharacterEncoding("utf-8");
       resp.setContentType("text/html;charset=utf-8");
        //获取前端页面发送来的请求参数
       /* String name = req.getParameter("name");
        String pwd = req.getParameter("pwd");
        String age = req.getParameter("age");*/
        Map<String, String[]> map = req.getParameterMap();
        Users user = new Users();  //为个user就是一个简单的javaBean
        try {
            BeanUtils.populate(user,map);//给bean对象 user中属性赋值(通过map,但map中key名称一定和javaBean中属性名一致)
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        //System.out.println("user = " + user);
        resp.getWriter().print(user);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}

Citys

package xyc.sjxy.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/city")
public class Citys extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //定义一个数组Citys
        String[] citys = new String[]{
                "新余", "南昌", "九江", "吉安", "上饶", "赣州"
        };
        //将citys存入到request域中
        req.setAttribute("citys",citys);

        //请求转发到jsp/array.jsp
        req.getRequestDispatcher("/jsp/array.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}

El01

package xyc.sjxy.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/el01")
public class El01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       req.setAttribute("user","user");
       req.getRequestDispatcher("/jsp/el02.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}

JavaBean

package xyc.sjxy.servlet;

import xyc.sjxy.pojo.City;
import xyc.sjxy.pojo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/bean01")
public class JavaBean extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建一个javaBean,然后存入到四大域:page,request,session,application
        //这里选择session域
        Users user = new Users();  //为个user就是一个简单的javaBean
        user.setId1(1001);
        user.setName("张三");
        user.setPwd("123");
        user.setSex(true);
        user.setAge(20);
        user.setHobby("运动,音乐,编程");

        //添加 这个对象的city属性

        user.setCity(new City("0502","新余"));

        //将上面javaBean存入到session域
        req.getSession().setAttribute("user",user);
        //重定向到页面:/jsp/javaBean.jsp
        resp.sendRedirect(req.getContextPath()+"/jsp/javabean.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}

Jstl02

package xyc.sjxy.servlet;

import xyc.sjxy.pojo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/jstl02")
public class Jstl02 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Users user = new Users();
        user.setName("admin1");
        user.setId1(1001);
        user.setPwd("123");
        user.setAge(20);
        req.setAttribute("user",user);
        req.getRequestDispatcher("/jsp/jstl02.jsp").forward(req,resp);
    }
}

List01

package xyc.sjxy.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@WebServlet("/list")
public class List01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //定义一个数组Citys
        String[] citys = new String[]{
                "新余", "南昌", "九江", "吉安", "上饶", "赣州"
        };
        //创建一个集合
        List<String> list=new ArrayList<String>(Arrays.asList(citys));
        //将这个list集合存入到application域中
        req.getServletContext().setAttribute("list",list);
        //重定向到页面:list.jsp
        resp.sendRedirect(req.getContextPath()+"/jsp/list.jsp");

        //list.get(0)  //list[0]

    }
}

Login

package xyc.sjxy.servlet;

import org.apache.commons.beanutils.BeanUtils;
import xyc.sjxy.pojo.LoginInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@WebServlet("/login")
public class Login extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取用户的帐号和密码
        Map<String, String[]> map = req.getParameterMap();
        LoginInfo loginInfo = new LoginInfo();

        try {
            BeanUtils.populate(loginInfo, map);
            loginInfo.setLoginName("张三");
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        if (loginInfo.getLoginId().equals("admin") &&
                loginInfo.getLoginPwd().equals("123")) {
            //将登录成功的用户信息存入到session域
            req.getSession().setAttribute("loginInfo", loginInfo);
            //重定向到首页:index.jsp
            resp.sendRedirect(req.getContextPath() + "/index.jsp");
        }else{
            //登录失败 请求转发到页面:/jsp/error.jsp  且在页面上显示“用户帐号或密码错误"
            req.setAttribute("msg","用户帐号或密码错误<a href="+req.getContextPath()+"/jsp/login.jsp>请重新登录</a>");
            req.getRequestDispatcher("/jsp/error.jsp").forward(req,resp);
        }
    }
}

UserList

package xyc.sjxy.servlet;

import org.apache.commons.beanutils.BeanUtils;
import xyc.sjxy.pojo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@WebServlet("/userList")
public class UserList extends HttpServlet {
    List<Users> list=new ArrayList<>();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Map<String, String[]> map = req.getParameterMap();
        Users user= new Users();
        try {
            BeanUtils.populate(user,map);
            list.add(user);
            req.setAttribute("users",list);
            //req.getAttribute("users"); //${users}
            req.getRequestDispatcher("/jsp/userList.jsp").forward(req,resp);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        //模拟users列表
        /*Users []users=new Users[]{
                new Users(1001,"tom1","123",true,20),
                new Users(1002,"tom2","123",true,20),
                new Users(1003,"tom3","123",true,22),
                new Users(1004,"tom4","123",true,26),
                new Users(1005,"tom5","123",true,20),
                new Users(1006,"tom6","123",true,29),
                new Users(1007,"tom7","123",true,30)
        };*/

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}

Demo

package xyc.sjxy.test;

import org.apache.commons.beanutils.BeanUtils;
import org.junit.Test;
import xyc.sjxy.pojo.Users;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

public class Demo {
    /*public static void main(String[] args) {

    }*/
    //用junit来进行单元测试
    @Test
    public void test01(){
        //测试javaBean
        Users user = new Users();  //为个user就是一个简单的javaBean
        user.setId1(1001);
        user.setName("张三");
        user.setPwd("123");
        user.setSex(true);
        user.setAge(20);
        System.out.println("user = " + user);
    }
    @Test
    public void test02() throws InvocationTargetException, IllegalAccessException {
        //测试javaBean
        Users user = new Users();  //为个user就是一个简单的javaBean
        BeanUtils.setProperty(user,"id1",1001);
        BeanUtils.setProperty(user,"name","张三");
        BeanUtils.setProperty(user,"sex",true);
        BeanUtils.setProperty(user,"age",20);
        System.out.println("user = " + user);
    }
    @Test
    public void test03() throws InvocationTargetException, IllegalAccessException {
        //测试javaBean
        Users user = new Users();  //为个user就是一个简单的javaBean
        Map map = new HashMap();
        map.put("id",1001);//map中key名称一定和javaBean中属性名一致,否则 赋值不会成功
        map.put("name","张三");
        map.put("pwd","123");
        map.put("sex",true);
        map.put("age",20);
        BeanUtils.populate(user,map);//给bean对象 user中属性赋值(通过map,但map中key名称一定和javaBean中属性名一致)
        System.out.println("user = " + user);
    }
}

add

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>
<body>
<div>
    <form action="${pageContext.request.contextPath}/userList">
        用户id:<input name="id1"> <br>
        名称:<input name="name"><br>
        密码:<input name="pwd" type="password"><br>
        性别:<input name="sex"><br>
        年龄:<input name="age"><br>
        <button type="submit">添加用户</button>
    </form>
</div>
</body>
</html>

array

<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>
<body>
${citys[0]}
${citys[1]}
${citys[2]}
${citys[3]}
${citys[4]}
${citys[5]}
${citys[6]}
</body>
</html>

bean

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>
<body>
<div>
    <form action="<%=request.getContextPath()%>/bean" method="post">
        用户Id<input name="id1"/><br>
        用户名称:<input name="name"/><br>
        用户密码:<input type="password" name="pwd"/><br>
        年龄:<input type="text" name="age">
        性别:<input type="radio"  name="sex" vckbox" name="hobby" value="编程">编程
        <br>
        <button type="submit">提交</button>alue="true"><input type="radio"  name="sex" value="false"><br>
        爱好:<input type="checkbox" name="hobby" value="运动">运动
        <input type="checkbox" name="hobby" value="音乐">音乐
        <input type="che
    </form>
</div>
</body>
</html>

el01

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>
<body>
<%
    pageContext.setAttribute("a","a");
    //从页面域中取属性a
   String a= (String) pageContext.getAttribute("a");
%>
\${a}=${a}
<hr>
<%=a%>
</body>
</html>

el02

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>
<body>

\${requestScope.user}=${requestScope.user}
\${requestScope.user}=${user}
<hr>
<%=request.getAttribute("user")%>
</body>
</html>

el_object

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<%
    request.getContextPath();
    String userpwd = request.getParameter("userpwd");
    String username = request.getParameter("username");

    Cookie userName = new Cookie("name","张三");
    Cookie userPwd = new Cookie("pwd","123");
    //将cookie写入浏览器中(内存)
    response.addCookie(userName);
    response.addCookie(userPwd);

%>
<%--
   pagecontext对象 和jsp的pageContext对象是同一个对象
--%>
<%--获取web应用的上下文路径:web应用的虚拟目录,即网站的发布目录--%>
${pageContext.request.contextPath} <br>

${sessionScope.a=12}
${a}
<%--四大域对象--%>
${pageScope} <br> <%--默认非空--%>
${requestScope} <br> <%--默认是空的--%>
${sessionScope} <br>   <%--默认是空的--%>
${applicationScope} <br>  <%--默认非空--%>

<%--获取请求参数--%>
${param.username}
${param.userpwd}
<hr>
${paramValues.username[0]}
${paramValues.userpwd[0]}
<%--获取请求头信息--%>
${header["user-agent"]} <br>
${headerValues["user-agent"][0]}
<%--获取cookie--%>
<hr>
${cookie.name.name}
${cookie.pwd.value}
<hr>
${initParam.encoding}
${initParam.webName}
</body>
</html>

error

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>
<body>
${msg}
</body>
</html>

javabean

<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>
<body>
<%--网页一般处理显示信息即可,尽量不做业务处理--%>
${sessionScope.user} <br>
<%--jsp引擎会自动查找四大域中有没有这个对象user:page--》request--》session-》application--null
 有点像jsp的pageContext的findAttribute()这个方法
 --%>
${user}
<br>
<%--实际上如果访问javaBean的属性它会调用:get和set--%>
${user.id1} <br>
${user.name} <br>
${user.sex} <br>
${user.age} <br>
${user.hobby} <br>
${user.city.cId} <br>
${user.city.cName} <br>
${user.city["cName"]} <br>
</body>
</html>

jstl01

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>
<%
    //pageContext.setAttribute("a",23);
%>
<body>
<%--${a=12}--%>
<%--将变量a的值以key-value对的形式存入到指定域环境中,默认存在page域中--%>
<c:set var="a" value="2345" scope="request"></c:set>
<c:out value="${a}"></c:out>
<%--<c:out value="hello" default="default">

</c:out>--%>
</body>
</html>

jstl02

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>
<body>
<%--<c:set value="2" var="a"></c:set>
<c:if test="${a>1}" var="result" scope="page">
    true
</c:if>
<c:out value="${result}"></c:out>--%>

<c:if test="${user.name eq 'admin' and user.pwd eq '123'}" var="result">
    <div>${result},登录成功,${user.name}</div>
</c:if>
<c:if test="${not (user.name eq 'admin' and user.pwd eq '123')}" var="result1">
    <div>${result1},登录失败,用户名或密码错误!</div>
</c:if>
</body>
</html>

jstl03

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>
<body>
<%--相当于输入一个成绩,判断成绩的等级:优,良,中,及格,不及格 --%>
<c:set value="57" var="score"></c:set>
<c:choose>
    <c:when test="${score ge 90}">
        <div></div>
    </c:when>
    <c:when test="${score ge 80}">
        <div></div>
    </c:when>
    <c:when test="${score ge 70}">
        <div></div>
    </c:when>
    <c:when test="${score ge 60}">
        <div>及格</div>
    </c:when>
    <c:otherwise>
        <div>不及格</div>
    </c:otherwise>
</c:choose>
</body>
</html>

jstl04

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>
<body>
<c:forEach var="i" begin="1" end="100" step="1" varStatus="status">
    <div>${i}</div>
    <div>序号:${status.index}</div>
</c:forEach>
</body>
</html>

list

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>
<body>
${list} <br>
${list[0]} <br>
${list[1]} <br>
${list[2]} <br>
${list[3]} <br>
${list[4]} <br>
${list[5]} <br>
${list[6]} <br>
</body>
</html>

login

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>
<%
    pageContext.getRequest();
    request.getContextPath();
%>
<body>
<div>
    <form action="${pageContext.request.contextPath}/login" method="post">
        用户帐号:<input name="loginId"/><br>
        用户密码:<input type="password" name="loginPwd"/><br>
        <button type="submit">登 录</button>
    </form>
</div>
</body>
</html>

userList

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
    <style>
        *{padding: 0;margin: 0}
        table {
            widht: 500px;
            margin:0 auto;
            border: 1px solid #ff6600;
            border-collapse: collapse;
        }
        table  tr,table th,table td{border: 1px solid #000}
    </style>
</head>
<body>
<table>
    <thead>
    <tr>
        <th>序号</th>
        <th>编号</th>
        <th>名称</th>
        <th>密码</th>
        <th>年龄</th>
        <th>性别</th>
    </tr>
    </thead>
    <tbody>
    <%--下面这个user是存放在页面域中的下对象javaBean,所以可以用el表达式来取它
    item属性对应的值是由域中某个对象
    --%>
    <c:forEach var="user" items="${users}" varStatus="status">
        <tr>
            <td>${status.index+1}</td>
            <td>${user.id1}</td>
            <td>${user.name}</td>
            <td>${user.pwd}</td>
            <td>${user.age}</td>
            <td>${user.sex}</td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div><a href="${pageContext.request.contextPath}/jsp/add.jsp">添加用户</a></div>
</body>
</html>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值