jsp的<a>超链接传值

11 篇文章 0 订阅

目录

jsp部分摘要

Servlet部分摘要

CommunityEventRegistrationService

CommunityEventRegistrationDao


jsp部分摘要

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

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

CommunityEventRegistrationDelete为指向的Servlet

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

Servlet部分摘要

int id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("username");


boolean isSuccess = cerService.update(communityeventregistration,s1.substring(7),id,name);
if(isSuccess) {
    request.setAttribute("msg", "删除成功!可刷新查看!");
}else {
    request.setAttribute("failMsg", "删除失败!");
}

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

然后id,name可以这样

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

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

CommunityEventRegistrationService

public class CommunityEventRegistrationService{
    private CommunityEventRegistrationDao cerDao = new CommunityEventRegistrationDao();
    public boolean update(CommunityEventRegistration communityeventregistration,String phone,int id,String name) {
        try {
            cerDao.update(communityeventregistration, phone, id, name);
            return true;
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        }
    }
}

CommunityEventRegistrationDao

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZYT_庄彦涛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值