zoukankan      html  css  js  c++  java
  • Filter案例

    package com.gqx.demo1;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.util.ArrayList;
    import java.util.List;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class AuthorityServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
         
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            String methodName=request.getParameter("method");
            //为了让一个servlet响应多个请求,这里可以使用反射
            try {
                Method method=getClass().getMethod(methodName, HttpServletRequest.class,HttpServletResponse.class);
                method.invoke(this, request,response);
            catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            this.doGet(request, response);
        }
         
        private UserDao userDao=new UserDao();
        //获取用户所有的信息
        public void getAuthorities(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            String userName=request.getParameter("username");
            User user =userDao.get(userName);
            request.setAttribute("user", user);
            request.setAttribute("authorities", userDao.getAuthorities());
            request.getRequestDispatcher("/authority-manager.jsp").forward(request, response);
        }
                                 
        public void updateAuthority(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            String username = request.getParameter("username");
         
                String [] authorities = request.getParameterValues("authority");
                List<Authority> authorityList = userDao.getAuthorities(authorities);
                 
                userDao.update(username, authorityList);
                response.sendRedirect(request.getContextPath() + "/authority-manager.jsp");
             
        }
         
    }
  • 相关阅读:
    C#中的配置文件自定义解析 [转帖]
    pagevisibility event
    [转] 翻译:web制作、开发人员需知的Web缓存知识
    离开和新的开始
    为什么我要自己写html5游戏引擎
    html5游戏长宽设置
    防止横竖屏时,iphone自动缩放的一段代码
    image to base64 工具
    一段代码,给游戏添加统一的封面和旋屏提示
    程序员应该具备的知识和技术(转)
  • 原文地址:https://www.cnblogs.com/zhangyubao/p/6973791.html
Copyright © 2011-2022 走看看