• jsp的<a>超连接传值


    目录

    jsp部分摘要

    Servlet部分摘要

    CommunityEventRegistrationService

    CommunityEventRegistrationDao


    jsp部分摘要

    1. <c:forEach items="${sessionScope.CommunityEventRegistrationList}" var="cer">
    2. <form class="form-horizontal" action="/CommunityEventRegistrationDelete" method="post">
    3. <a class="btn btn-danger" href="/CommunityEventRegistrationDelete?id=1&username=${cer.username }">
    4. 删除
    5. </a>
    6. </form>
    7. </c:forEach>

    其中href="/CommunityEventRegistrationDelete?id=1&username=${cer.username }"

    CommunityEventRegistrationDelete为指向的Servlet

    传两个值,一个是id,一个是username。【这里展示的是两种不同形式】

    Servlet部分摘要

    1. int id = Integer.parseInt(request.getParameter("id"));
    2. String name = request.getParameter("username");
    3. boolean isSuccess = cerService.update(communityeventregistration,s1.substring(7),id,name);
    4. if(isSuccess) {
    5. request.setAttribute("msg", "删除成功!可刷新查看!");
    6. }else {
    7. request.setAttribute("failMsg", "删除失败!");
    8. }

    jsp传值过来后,Servlet就用request.getParameter("???");来接收

    然后id,name可以这样

    boolean isSuccess = cerService.update(communityeventregistration,s1.substring(7),id,name);

    塞在后面,传值进Service类使用方法进入后续操作

    CommunityEventRegistrationService

    1. public class CommunityEventRegistrationService{
    2. private CommunityEventRegistrationDao cerDao = new CommunityEventRegistrationDao();
    3. public boolean update(CommunityEventRegistration communityeventregistration,String phone,int id,String name) {
    4. try {
    5. cerDao.update(communityeventregistration, phone, id, name);
    6. return true;
    7. } catch (SQLException e) {
    8. // TODO Auto-generated catch block
    9. e.printStackTrace();
    10. return false;
    11. }
    12. }
    13. }

    CommunityEventRegistrationDao

    1. public class CommunityEventRegistrationDao {
    2. public void update(CommunityEventRegistration communityeventregistration, String phone,int id, String username) throws SQLException {
    3. QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
    4. System.out.println("update在此1");
    5. if(id==1){
    6. System.out.println("update在此2");
    7. String sql = "update `communityeventregistration` set yoga='-----' where phone = ? and username=? and yoga= '√'";
    8. r.update(sql,phone,username);
    9. }
    10. }
    11. }

  • 相关阅读:
    Redis学习之Redis概述及原理、基本操作及持久化
    白话 TBW 是什么?
    点击化学 PEG 试剂:1802907-92-1,Mtz-PEG4-NHS,甲基四嗪-四聚乙醇-活性酯
    Java基础 --- 创建线程
    Istio 升级后踩的坑
    二分查找一看就会,一写就废?
    高并发系统谨防被一行日志击垮
    Redis支持的数据类型
    【LeetCode】1282. 用户分组
    访问控制列表ACL讲解——想偷偷访问数据,我ACL可不同意
  • 原文地址:https://blog.csdn.net/weixin_45528773/article/details/134022767