首页 > 其他分享 >今日总结

今日总结

时间:2023-03-11 22:25:06浏览次数:37  
标签:总结 list request getParameter method 今日 servlet response

今天复习了Javaservlet的相关内容

package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.Bean;
import dao.Dao;
/**
 * Servlet implementation class servlet
 */
@WebServlet("/servlet")
public class HttpServlet extends javax.servlet.http.HttpServlet {
    Dao dao=new Dao();
    private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HttpServlet() {
        super();
        // TODO Auto-generated constructor stub
    }


    private void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        request.setCharacterEncoding("utf-8");
        int id = Integer.parseInt(request.getParameter("id"));
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        String sex = request.getParameter("sex");
        Bean bean=new Bean(id,name,password,sex);
        dao.update(bean);
        request.setAttribute("message", "修改成功");
        request.getRequestDispatcher("servlet?method=list").forward(request, response);
    }

    private void list(HttpServletRequest request, HttpServletResponse response) throws Exception {
        // TODO Auto-generated method stub
        request.setCharacterEncoding("utf-8");
        List<Bean> list = dao.list();
        request.setAttribute("list", list);
        request.getRequestDispatcher("list.jsp").forward(request,response);
    }

    private void delete(HttpServletRequest request, HttpServletResponse response) throws Exception, IOException {
        // TODO Auto-generated method stub
        request.setCharacterEncoding("UTF-8");
        int id=Integer.parseInt(request.getParameter("id"));
        dao.delete(id); //进行数据库的删除操作
        request.setAttribute("message", "删除成功");
        request.getRequestDispatcher("servlet?method=list").forward(request, response);
    }

    private void insert(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        // TODO Auto-generated method stub
        request.setCharacterEncoding("utf-8");
        int id = Integer.parseInt(request.getParameter("id"));
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        String sex = request.getParameter("sex");
        Bean bean=new Bean(id,name,password,sex);
        if(dao.insert(bean)) {
            request.setAttribute("message", "添加成功");
            request.getRequestDispatcher("index.jsp").forward(request, response);
        }
    }
    
    

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        request.setCharacterEncoding("utf-8");
        String method=request.getParameter("method");
        if("insert".equals(method)) {
            insert(request,response);
            
        }
        else if("delete".equals(method)) {
            try {
                delete(request,response);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
        }
        else if("update".equals(method)) {
            update(request,response);
        }
        else if("list".equals(method)) {
            try {
                list(request,response);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

 

标签:总结,list,request,getParameter,method,今日,servlet,response
From: https://www.cnblogs.com/zhaoyueheng/p/17207169.html

相关文章

  • 2023/3/11 考试总结
    时间安排7.30~8.00询问很复杂,但是数据随机。直觉告诉我,直接暴力就是对的。写了个set把每个区间存在它的最大值和最小值位置上,然后暴力修改,但是大样例跑了很久。8.00~9......
  • 2023/3/11杂题总结(未完)
    ELCA这道题的整体思路就是,对于一个lct,我们能够维护的东西,需要保证能够在较优的时间内完成实边修改和区间合并(就是得保证支持实虚边转化和平衡树的维护),那么这道题,......
  • 2022/3/11 考试总结
    时间安排7.30~8.00先看T1,感觉是某种很典的模型,想了个做法,建出dfs树跑树形dp。样例过了,因为暴力很难写而且还要SPj就直接交了。8.00~10.00推了推T2,感觉解是惟一的,于是......
  • 3.11今日总结
    今天学习了安卓的日期控件CardDatePickerDialog.builder(this).setTitle("SETMAXDATE").setOnChoose(listener=object:CardDatePi......
  • 3.10今日总结
    因为H5页面在移动端的兼容性及扩展性方面体现出来的优势,又兼得APP中植入H5页面相应用的灵活性有大大的提升(如活动、游戏的更新等)。APP开发不可避免的须要载入一些H5页面。......
  • PMP项目变更管理及变更流程总结
    转载请注明出处:1. 变更管理流程           2.变更管理流程十步:0预防--1发起变更请求--2分析影响--3备选方案--4CCB批准--5更新项目管理计划......
  • 今日报告-20
    今日打卡所花时间(包括上课):3h代码量(行):100发表博客:2篇(不包括本篇)了解到的知识点:今天主要学到的知识是BroadcastReceiver,实现了监听电量变化的广播,还学习了许多种类型的......
  • 3.11号今日总结
    1.基本用法与事件处理:1)RadioButton(单选按钮)如题单选按钮,就是只能够选中一个,所以我们需要把RadioButton放到RadioGroup按钮组中,从而实现单选功能!先熟悉下如何使用Rad......
  • 2023/3/8 && 2023/3/11 模拟总结
    开摆,嘿嘿,开摆!2023/3/8IOI赛制/6道题/部分文件io集训期间的第一次模拟,看到是IOI赛制感觉好拿分,于是就挺放松的。开考之后看到T1,胡了一个二维前缀和暴力做法,爽拿3......
  • 今日份乐子2
    ......