JAVAWEB 一一 userweb1(原生,非servlet版,用doXXX.jsp代替servlet)

创建数据库和表

首先,创建一个web项目

然后引入jar包

创建jsp页面

创建包

创建接口

实现类

详细内容

首先创建一个登陆页面 login.jsp

<%@ page language="java" import="java.util.*" pageEncoding="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>
    <form action="jsp/dologin.jsp" method="post">
        用户名:<input type="text" name="username"/><br/>
        密码 :<input type="password" name="password"/> <br/>
        <input type="submit" value="登录"/>    
        <input type="reset" value="重置"/>
       </form>
  </body>
</html>

  

创建要跳转的页面 (充当半个控制器servlet)  dologin.jsp

User

entity层

实体类

User.java

get set 方法 有参无参构造器

 1 package com.user.entity;
 2
 3 public class User {
 4
 5     private String username;
 6     private String password;
 7     private String job;
 8     private String email;
 9     private int age;
10     public String getUsername() {
11         return username;
12     }
13     public void setUsername(String username) {
14         this.username = username;
15     }
16     public String getPassword() {
17         return password;
18     }
19     public void setPassword(String password) {
20         this.password = password;
21     }
22     public String getJob() {
23         return job;
24     }
25     public void setJob(String job) {
26         this.job = job;
27     }
28     public String getEmail() {
29         return email;
30     }
31     public void setEmail(String email) {
32         this.email = email;
33     }
34     public int getAge() {
35         return age;
36     }
37     public void setAge(int age) {
38         this.age = age;
39     }
40     public User(String username, String password, String job, String email,
41             int age) {
42         super();
43         this.username = username;
44         this.password = password;
45         this.job = job;
46         this.email = email;
47         this.age = age;
48     }
49     public User() {
50         super();
51     }
52
53 }

  

service层

接口 UserService.java

package com.user.service;

public interface UserService {

    public boolean isLogin(String username,String password);
}

  

实现类 UserServiceImpl.java



package com.user.service.impl;

import com.user.dao.UserDao;
import com.user.dao.impl.UserDaoImpl;
import com.user.entity.User;
import com.user.service.UserService;

public class UserServiceImpl implements UserService {

    public boolean isLogin(String username, String password) {

        UserDao userDao = new UserDaoImpl();
        User user = userDao.getUserByName(username);
        if(user!=null){
            String pwd= user.getPassword();
            if(pwd.equals(password)){
                return true;
            }
            return false;

        }else{
            return false;
        }
    }

 

dao层

接口 UserDao.java

1 package com.user.dao;
2
3 import com.user.entity.User;
4
5 public interface UserDao {
6
7     public User getUserByName(String username);
8
9 }

  

实现类 UserDaoImpl.java

 1 package com.user.dao.impl;
 2
 3 import java.sql.ResultSet;
 4 import java.sql.SQLException;
 5
 6 import com.user.dao.BaseDao;
 7 import com.user.dao.UserDao;
 8 import com.user.entity.User;
 9
10 public class UserDaoImpl implements UserDao {
11     BaseDao dao = new BaseDao();
12     public User getUserByName(String username) {
13         //
14         String sql ="select * from users where username = ?";
15         Object [] obj = new Object[]{ username};
16         ResultSet rs = dao.executeQuery(sql, obj);
17         User user  =null;
18         try {
19             while(rs.next()){
20                 String password = rs.getString("password");
21                 String job = rs.getString("job");
22                 String email = rs.getString("email");
23                 int age = rs.getInt("age");
24                 user = new User(username, password, job, email, age);
25             }
26             return user;
27         } catch (SQLException e) {
28             // TODO Auto-generated catch block
29             e.printStackTrace();
30         }finally{
31             dao.closeConnection();
32         }
33         return null;
34     }
35
36 }

dao层  

basedao,java

package com.user.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
 * 数据库操作的基类
 * @author YangKe
 *
 */
public class BaseDao {

    protected Connection conn;
    protected PreparedStatement ps;
    protected ResultSet rs;
    protected String sql;
    //获取连接
    public Connection getConnection(){
        try {
            //获取上下文对象
            Context ctx = new InitialContext();
            //从上下文中查找数据源
            DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/emp");
            //从数据源中获取连接
            conn = ds.getConnection();
        } catch (NamingException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }

    //关闭连接释放资源
    public void closeConnection(){
        if(rs!=null){
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(ps!=null){
            try {
                ps.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(conn!=null){
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    //通过JDBC来对数据库进行查询操作
    public ResultSet executeQuery(String sql, Object[] obj ){
        //获取连接
        conn = getConnection();
        try {
            //预编译SQL
            ps= conn.prepareStatement(sql);
            for (int i = 0; i < obj.length; i++) {
                //给占位符赋值
                ps.setObject(i+1, obj[i]);
            }
            //执行SQL语句,获取结果集
            rs = ps.executeQuery();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return rs;
    }
    //通过JDBC来对数据库进行更新操作
    public boolean executeUpdate(String sql, Object[] obj ){
        //获取连接
        conn = getConnection();
        try {
            //预编译SQL
            ps= conn.prepareStatement(sql);
            for (int i = 0; i < obj.length; i++) {
                //给占位符赋值
                ps.setObject(i+1, obj[i]);
            }
            //执行SQL语句,获取该更新语句实际影响的行数
            int count = ps.executeUpdate();
            //如果行数大于0,表示更新操作成功
            if(count>0){
                return true;
            //否则表示更新操作失败
            }else{
                return false;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }
}

  

dologin页面

<%@page import="com.user.service.impl.UserServiceImpl"%>
<%@page import="com.user.service.UserService"%>
<%@ page language="java" import="java.util.*" pageEncoding="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 ‘dologin.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>
    <%
    //dologin相当于一个servlet
    //设置前台页面参数  编码格式
        request.setCharacterEncoding("UTF-8");
        //获取前台页面参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        //  调用Service 层方法 判断是否成功
        UserService service = new UserServiceImpl();
        boolean islogin = service.isLogin(username, password);

        if(islogin){//登录成功 跳转到sucess.jsp页面 否则 跳转到login.jsp
        //转发
            request.getRequestDispatcher("success.jsp").forward(request,response);

        }else{//登录失败
            //重定向
            response.sendRedirect("Login.jsp");
        }

    %>
  </body>
</html>

  

success .jsp

<%@ page language="java" import="java.util.*" pageEncoding="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 ‘success.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><br>
  </body>
</html>

  

也可以直接跳转到别的页面比如list.jsp 一个雇员信息列表的页面 但是  这个页面的数据是从数据库查出来的(这样才是动态页面啊)

那么就需要再做一遍上面的步骤  (创建Emp接口和实现类 还有dolist页面 list页面)

Emp

entity层

Emp.java

package com.user.entity;

import java.util.Date;

public class Emp {
    private int empno;
    private String ename;
    private String job;
    private int mgr;
    private Date hiredate;
    private double sal;
    private double comm;
    private int deptno;

    public Emp() {
        super();
    }
    public Emp(int empno, String ename, String job, int mgr, Date hiredate,
            double sal, double comm, int deptno) {
        super();
        this.empno = empno;
        this.ename = ename;
        this.job = job;
        this.mgr = mgr;
        this.hiredate = hiredate;
        this.sal = sal;
        this.comm = comm;
        this.deptno = deptno;
    }

    public int getEmpno() {
        return empno;
    }
    public void setEmpno(int empno) {
        this.empno = empno;
    }
    public String getEname() {
        return ename;
    }
    public void setEname(String ename) {
        this.ename = ename;
    }
    public String getJob() {
        return job;
    }
    public void setJob(String job) {
        this.job = job;
    }
    public int getMgr() {
        return mgr;
    }
    public void setMgr(int mgr) {
        this.mgr = mgr;
    }
    public Date getHiredate() {
        return hiredate;
    }
    public void setHiredate(Date hiredate) {
        this.hiredate = hiredate;
    }
    public double getSal() {
        return sal;
    }
    public void setSal(double sal) {
        this.sal = sal;
    }
    public double getComm() {
        return comm;
    }
    public void setComm(double comm) {
        this.comm = comm;
    }
    public int getDeptno() {
        return deptno;
    }
    public void setDeptno(int deptno) {
        this.deptno = deptno;
    }
}

  

service层

接口 EmpService.java

package com.user.service;

import java.util.List;

import com.user.entity.Emp;

/**
 * @author YangKe
 *
 */
public interface EmpService {

    public List<Emp> getEmpList();

    public Emp getEmpById(int empno);

    public List<Emp> getEmpByName(String ename);

    public boolean addEmp(Emp emp);

    public boolean updateEmp(Emp emp);

    public boolean delEmpById(int empno);

}

  

实现类 EmpServiceImpl

package com.user.service.impl;

import java.util.List;

import com.user.dao.EmpDao;
import com.user.dao.impl.EmpDaoImpl;
import com.user.entity.Emp;
import com.user.service.EmpService;

public class EmpServiceImpl implements EmpService {

    EmpDao dao = new EmpDaoImpl();
    public List<Emp> getEmpList() {
        // TODO Auto-generated method stub

        return dao.getEmpList();
    }

    public Emp getEmpById(int empno) {
        // TODO Auto-generated method stub
        return null;
    }

    public List<Emp> getEmpByName(String ename) {
        // TODO Auto-generated method stub
        return null;
    }

    public boolean addEmp(Emp emp) {
        return dao.addEmp(emp);
    }

    public boolean updateEmp(Emp emp) {
        // TODO Auto-generated method stub
        return false;
    }

    public boolean delEmpById(int empno) {
        // TODO Auto-generated method stub
        return false;
    }

}

  

dao层

接口 EmpDao.java

package com.user.dao;

import java.util.List;

import com.user.entity.Emp;

public interface EmpDao {
    //获取雇员列表
    public List<Emp> getEmpList();
    //根据雇员编号查某个雇员
    public Emp getEmpByNo(int empno);
    //根据名字来查雇员
    public List<Emp> getEmpByName(String name);
    //新增雇员
    public boolean addEmp(Emp emp);
    //修改雇员
    public boolean updateEmp(Emp emp);
    //删除雇员
    public boolean delEmpById(int empno);
}

  

实现类 EmpDaoImpl.java

package com.user.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.user.dao.BaseDao;
import com.user.dao.EmpDao;
import com.user.entity.Emp;

public class EmpDaoImpl implements EmpDao {

    BaseDao dao = new BaseDao();
    public List<Emp> getEmpList() {
        String sql = "select * from emp ";
        Object [] obj = new Object[]{};
        ResultSet rs = dao.executeQuery(sql, obj);
        List<Emp> list = new ArrayList<Emp>();
        try {
            while(rs.next()){

                String ename = rs.getString("ename");
                int empno =rs.getInt("empno");
                String job = rs.getString("job");
                int mgr  = rs.getInt("mgr");
                Date hiredate = rs.getDate("hiredate");
                double sal = rs.getDouble("sal");
                double comm = rs.getDouble("comm");
                int deptno = rs.getInt("deptno");
                Emp emp = new Emp(empno, ename, job, mgr, hiredate, sal, comm, deptno);
                list.add(emp);
            }
            return list;
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return null;
    }

    public Emp getEmpByNo(int empno) {
        // TODO Auto-generated method stub
        return null;
    }

    public List<Emp> getEmpByName(String name) {
        // TODO Auto-generated method stub
        return null;
    }

    public boolean addEmp(Emp emp) {
        String sql = "insert into emp(empno,ename,job,mgr,sal,comm,deptno) values(?,?,?,?,?,?,?)";
        Object[] obj = new Object[] { emp.getEmpno(), emp.getEname(),
                emp.getJob(), emp.getMgr(), emp.getSal(), emp.getComm(),
                emp.getDeptno() };
        return dao.executeUpdate(sql, obj);
    }

    public boolean updateEmp(Emp emp) {
        // TODO Auto-generated method stub
        return false;
    }

    public boolean delEmpById(int empno) {
        // TODO Auto-generated method stub
        String sql = "delete from emp where empno= ?";
        Object[]obj = new Object[]{empno};

        return dao.executeUpdate(sql, obj);

    }

}

  

dolist.jsp

这个页面的数据是从数据库查出来的(这样才是动态页面啊)

所以 我们需要跳转到一个dolist页面 (充当servlet)让他把页面从数据来出来后跳转到list页面

<%@page import="com.user.entity.Emp"%>
<%@page import="com.user.service.EmpService"%>
<%@page import="com.user.service.impl.EmpServiceImpl"%>
<%@ page language="java" import="java.util.*" pageEncoding="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 ‘dolist.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>
    <%
    //设置前台页面参数  编码格式
       request.setCharacterEncoding("UTF-8");

    EmpService service =new EmpServiceImpl();
    List<Emp>list=service.getEmpList();
    //转发到list。jsp
    request.setAttribute("list", list);
    request.getRequestDispatcher("list.jsp").forward(request, response);

    %>
  </body>
</html>

  

list.jsp

<%@page import="com.user.entity.Emp"%>
<%@ page language="java" import="java.util.*" pageEncoding="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 ‘list.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>
      <a href="jsp/addEmp.jsp" 新增雇员>新增雇员</a>
    <table bordercolor="red" boder="1px">
        <thead>
            <tr>
                <td>雇员编号</td>
                <td>雇员姓名</td>
                <td>工作</td>
                <td>经理编号</td>
                <td>入职日期</td>
                <td>薪水</td>
                <td>津贴</td>
                <td>部门编号</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <%
            request.setCharacterEncoding("UTF-8");

            List<Emp>list=(List<Emp>)request.getAttribute("list");
            for(int i = 0; i<list.size();i++){
            Emp emp = list.get(i);

            %>
            <tr>
                <td><%=emp.getEmpno()%></td>
                <td><%=emp.getEname()%></td>
                <td><%=emp.getJob()%></td>
                <td><%=emp.getMgr()%></td>
                <td><%=emp.getHiredate()%></td>
                <td><%=emp.getSal()%></td>
                <td><%=emp.getComm()%></td>
                <td><%=emp.getDeptno()%></td>
                <td>
                <a href="#">修改</a>
                <a href="jsp/dodel.jsp?empno=<%=emp.getEmpno()%>">删除</a>
                </td>
            </tr>

        </tbody>

              <%}%>
    </table>
     <br>
  </body>
</html>

  

查以上就是一个查( public List<Emp> getEmpList() )的步骤

那么 增删改 也一样 都是一个更新操作(dao.executeUpdate(sql, obj);)

不同之处在于 增删改 都是对数据库进行了修改(dao.executeUpdate(sql, obj);)

然后执行查的操作 最终跳转到dolist.jsp →list.jsp 页面

在list展示页面 a标签对应的一个添加雇员的页面

增:

addEmp.jsp

<%@ page language="java" import="java.util.*" pageEncoding="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 ‘addEmp.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>
   <form action="jsp/doadd.jsp">
       员工编号<input name ="empno"/><br/>
       员工姓名<input name ="ename"/><br/>
       员工工作<input name ="job"/><br/>
       经理编号<input name ="mgr"/><br/>
       入职日期<input name ="hiredate"/><br/>
       薪水<input name ="sal"/><br/>
       部门编号<input name ="deptno"/><br/>
       <input type="submit" value="提交"/>
       <input type="reset" value="重置"/><br/>
       </form>
  </body>
</html>

  

doadd .jsp

<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="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 ‘doadd.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>
    <%
                request.setCharacterEncoding("UTF-8");
                String empnoStr=request.getParameter("empno");
                String ename=request.getParameter("ename");
                String job=request.getParameter("job");
                String mgrStr=request.getParameter("mgr");
        //        String hiredateStr=request.getParameter("hiredate");
                String salStr=request.getParameter("sal");
                String deptnoStr=request.getParameter("deptno");
                //格式转化
                int empno = Integer.parseInt(empnoStr);
            //    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

                int mgr = Integer.parseInt(mgrStr);
            //    Date hiredate = sdf.parse(hiredateStr);
                double sal = Double.parseDouble(salStr);
                int deptno= Integer.parseInt(deptnoStr);
                // 封装
                Emp emp  = new Emp(empno,ename,job,mgr,sal,deptno);
                EmpService service = new EmpServiceImpl();
                boolean isAdd = service.addEmp(emp);
//                 if(isAdd){

//                 }else{
//                 }
                response.sendRedirect("dolist.jsp");
    %>
  </body>
</html>

  

  

dolist.jsp

<%@page import="com.user.entity.Emp"%>
<%@page import="com.user.service.EmpService"%>
<%@page import="com.user.service.impl.EmpServiceImpl"%>
<%@ page language="java" import="java.util.*" pageEncoding="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 ‘dolist.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>
    <%
    //设置前台页面参数  编码格式
       request.setCharacterEncoding("UTF-8");

    EmpService service =new EmpServiceImpl();
    List<Emp>list=service.getEmpList();
    //转发到list。jsp
    request.setAttribute("list", list);
    request.getRequestDispatcher("list.jsp").forward(request, response);

    %>
  </body>
</html>

  

list.jsp

<%@page import="com.user.entity.Emp"%>
<%@ page language="java" import="java.util.*" pageEncoding="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 ‘list.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>
      <a href="jsp/addEmp.jsp" 新增雇员>新增雇员</a>
    <table bordercolor="red" boder="1px">
        <thead>
            <tr>
                <td>雇员编号</td>
                <td>雇员姓名</td>
                <td>工作</td>
                <td>经理编号</td>
                <td>入职日期</td>
                <td>薪水</td>
                <td>津贴</td>
                <td>部门编号</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <%
            request.setCharacterEncoding("UTF-8");

            List<Emp>list=(List<Emp>)request.getAttribute("list");
            for(int i = 0; i<list.size();i++){
            Emp emp = list.get(i);

            %>
            <tr>
                <td><%=emp.getEmpno()%></td>
                <td><%=emp.getEname()%></td>
                <td><%=emp.getJob()%></td>
                <td><%=emp.getMgr()%></td>
                <td><%=emp.getHiredate()%></td>
                <td><%=emp.getSal()%></td>
                <td><%=emp.getComm()%></td>
                <td><%=emp.getDeptno()%></td>
                <td>
                <a href="#">修改</a>
                <a href="jsp/dodel.jsp?empno=<%=emp.getEmpno()%>">删除</a>
                </td>
            </tr>

        </tbody>

              <%}%>
    </table>
     <br>
  </body>
</html>

  

  

时间: 2024-10-20 16:31:13

JAVAWEB 一一 userweb1(原生,非servlet版,用doXXX.jsp代替servlet)的相关文章

Servlet是什么?JSP和Servlet的区别。Servlet的生命周期。

Servlet(Server Applet),全称Java Servlet, 是用Java编写的服务器端程序.而这些Sevlet都要实现Servlet这个借口.其主要功能在于交互式地浏览和修改数据,生成动态Web内容.Servlet运行于支持Java的应用服务器中. HttpServlet 重写doGet和doPost方法或者你也可以重写service方法完成对get和post请求的响应. 2.JSP和Servlet的区别 JSP经编译后就变成了“类servlet”. JSP由HTML代码和JS

JSP和servlet有什么区别?

JSP和servlet有什么区别? JSP是Servlet技术的扩展,本质上是Servlet的简易方式,更强调应用的外表表达. JSP编译后是"类servlet". Servlet和JSP最主要的不同点: 1.  Servlet的应用逻辑是在Java文件中,并且完全从表示层中的HTML里分离开来. 2. JSP的情况是Java和HTML可以组合成一个扩展名为.jsp的文件. 3. JSP侧重于视图,Servlet主要用于控制逻辑

jsp和servlet的联系与区别

刚开始接触jsp和servlet的时候,觉得这两个完全没什么联系,还是太天真 jsp实际上就是servlet,可以说jsp和servlet是同一种东西,只是不同的表现形式罢了. tomcat会将jsp最终转化成一个servlet,我们可以去tomcat下work目录下看出一点端倪,如下图: 发现index.jsp最终转化成了一个java文件.所以实际上jsp和servlet就是同一个东西,只是不同的表现形式. 客户端访问,都是请求的服务器,没有跟servlet打交道,tomcat服务器然后组装请

【转】jsp 和 servlet的联系和区别

简单的说,SUN首先发展出SERVLET,其功能比较强劲,体系设计也很先进,只是,它输出HTML语句还是采用了老的CGI方式,是一句一句输出,所以,编写和修改HTML非常不方便. 后来SUN推出了类似于ASP的镶嵌型的JSP,把JSP TAG镶嵌到HTML语句中,这样,就大大简化和方便了网页的设计和修改.新型的网络语言如ASP,PHP,JSP都是镶嵌型的SCRIPT语言. JSP在本质上就是SERVLET,但是两者的创建方式不一样. Servlet完全是JAVA程序代码构成,擅长于流程控制和事务

MyEclipse2014配置Tomcat开发JavaWeb程序JSP以及Servlet(转载)

转载地址:http://blog.csdn.net/21aspnet/article/details/21867241 1.安装准备 1).下载安装MyEclipse2014,这已经是最新版本. 2).下载Tomcat 官网:http://tomcat.apache.org/ 我们选择8.0: http://tomcat.apache.org/download-80.cgi 在windows下选择64位解压版:http://mirror.bit.edu.cn/apache/tomcat/tomc

MyEclipse2014配置Tomcat开发JavaWeb程序JSP以及Servlet

1.安装准备 1).下载安装MyEclipse2014,这已经是最新版本. 2).下载Tomcat 官网:http://tomcat.apache.org/ 我们选择8.0: http://tomcat.apache.org/download-80.cgi 在windows下选择64位解压版:http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.0.3/bin/apache-tomcat-8.0.3-windows-x64.zip 下载好以后在本地

(转)MyEclipse2014配置Tomcat开发JavaWeb程序JSP以及Servlet

1.安装准备 1).下载安装MyEclipse2014,这已经是最新版本. 2).下载Tomcat 官网:http://tomcat.apache.org/ 我们选择8.0: http://tomcat.apache.org/download-80.cgi 在windows下选择64位解压版:http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.0.3/bin/apache-tomcat-8.0.3-windows-x64.zip 下载好以后在本地

购物车非cookie版

2015.11.26购物车,非cookie版 [点击来,你发现被骗了(笑哭,笑哭,笑哭,源代码的话,留下邮箱吧,是在不好找这一时半会儿的.)] Jsp通过反射机制获取bean中的标签,但其实,可以没有真实的属性与之对应.只要是符合getset方法设置的名字,就可以通过el表达式在jsp页面中获取. 更新核心代码: private void update(HttpServletRequest request, HttpServletResponse response) throws Servlet

POJ 1780 Code (欧拉回路+非递归版dfs)

题目地址:POJ 1780 还是求序列的欧拉回路.只不过这题有两坑. 第一坑是用数字来当点的话,会MLE,因为每个数字可以连10条边,100w条边会MLE,即使用vector也会TLE.这题可以用边来记录,对于n为1时直接输出,然后后面的,比如12,23这两个点就用边权值为123来表示这两个点,这样就把点和边的范围都缩小了10倍. 第二坑是用递归的dfs会爆栈,亲测即使加手扩栈也会爆..(简直丧心病狂..)需要用非递归版dfs,也不难,dfs本身就是利用的栈,所以改成栈的形式就可以了. 代码如下