• 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. }

  • 相关阅读:
    vue3【toRef和toRefs--详】
    云部署家里的服务器
    C的char溢出
    加固技术护城河,比亚迪商用车加速领跑全球电动化进程
    JAVA:实现AES算法(附完整源码)
    最长公共子序列 递归
    Python异步编程之web框架 异步vs同步 数据库IO任务并发支持对比
    理解Gumbel softmax trick
    一般处理程序ashx接入微信服务器配置
    vue wangEditor富文本编辑器 默认显示与自定义工具栏配置
  • 原文地址:https://blog.csdn.net/weixin_45528773/article/details/134022767