JavaEE_JSP_完整的JSTL+EL表达式将数据显示出来的流程(转载)

总共分为五个部分,

1.EL+JSTL前端JSP页面

2.servlet(传递数据)

3.dao(操作数据库)

4.javaBean(ORM)

5.数据库表设计

 

1.EL+JSTL前端JSP页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%-- page import="com.user.bean.VimUserInformationObject" --%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  
<%
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>用户权限管理</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>
  <div>
 <span style="color:red;font-weight:bold">
 	<%
 	 if(session.getAttribute("login_user")!=null){
 	 out.println("尊敬的"+session.getAttribute("login_user")+"<br/>");
 	 }
     %>
  </span>
  </div>
  <div>
  	<a href="user/normal/servlet/loginOutUser">-注销-</a>
  	<a href="jsp/user/modify_password.jsp">-修改密码-</a>
  </div>
  <div>
  	  <div>
  	  	<span style="color:red;font-weight:bold">
 			<%
 	 			if(request.getAttribute("tips")!=null){
 	 				out.println(request.getAttribute("tips")+"<br/>");
 	 			}
    	 	%>
    	 </span>
  	  </div>
      <form method="post" action="">
          <table>
              <tr>
                  <td>序号</td>
                  <td>用户名</td>
                  <td>权限</td>
              </tr>
              <c:forEach items="${allUserAuthority}" var="item" varStatus="current">
              	<tr>
              		<td>${current.index}</td>
              		<td>${item.user_name}</td>
              		<td>${item.authority}</td>
              	</tr>
              </c:forEach>
              <!-- 
              	${item['user_name']}
              	${item['authority']}
              	 -->
              <!--
                <tr>
                  <td>1</td>
                  <td>szh</td>
                  <td><input name="username" type="checkbox"/></td>
                  <td><input type="checkbox"/></td>
              </tr> 
               -->
           
          </table>
          <!-- 
          <input type="submit" value="确认删除" οnclick="return confirm('确认删除?');"/>
          <input type="reset" value="重选"> 
           -->
      </form>
  </div>
  </body>
</html>

2.servlet

package com.user.manage.servlet;

import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.user.bean.VimUserInformationObject;
import com.user.dao.MultUserInformationDao;

public class ManagerUserAuthorityServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	/**
	 * Constructor of the object.
	 */
	public ManagerUserAuthorityServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * Initialization of the servlet. <br>
	 * 
	 * @throws ServletException
	 *             if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

	// 响应客户端请求的方法
	public void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, java.io.IOException {
		String tips = "";
		// Servlet本身并不输出响应到客户端,因此必须将请求转发到视图页面
		RequestDispatcher rd;

		try {
			MultUserInformationDao userInformationDao = new MultUserInformationDao();

			// 暂时将所有用户的数据放到登录Servlet处理,之后进行优化
			List<VimUserInformationObject> allUserAuthorityObjects = userInformationDao
					.query();
			request.setAttribute("allUserAuthority", allUserAuthorityObjects);
			//
			//

			// 获取转发对象
			rd = request
					.getRequestDispatcher("/WEB-INF/jsp/user/manager_authority.jsp");
			rd.forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

引☞https://blog.csdn.net/u010003835/article/details/50108255?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522161104812316780265460373%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=161104812316780265460373&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_v2~rank_v29-5-50108255.pc_search_result_no_baidu_js&utm_term=j2ee%20el%E8%A1%A8%E8%BE%BE%E5%BC%8F&spm=1018.2226.3001.4187

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值