Ajax+servlet练习题

发布时间:2022-07-05 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Ajax+servlet练习题脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

完成商品购买功能

 

Ajax+servlet练习题

 

 

 apple.jsp:

@H_360_15@
<%@ page language="java" contentTyPE="text/htML; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PubLIC "-//W3C//DTD HTML 4.01 TransITional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<;meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery-3.6.0.js"></script>
<script type="text/javascript">
    $(function(){
        num=$(".num").val();
        DOSum=function(){
            $.get('AppleController?num='+num,function(data){
               alert("一共"+data+"元。");
                console.LOG("购买"+num+"个,一共"+data+"元。");
            })
        }
    });
</script>
<title>苹果</title>
</head>
<body>
    <h1>苹果店</h1>
    <h2>5元1个苹果</h2>
    <input class="num" type="text" size=12 placeholder="输入"/>
    <input type="button" value="提交" onclick="dosum()"/>
</body>
</html>

AppleController.java

PRotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int num = Integer.parseint(request.getParameter("num"));
        PrintWriter pw=response.getWriter();
        pw.print(num*5);
        pw.flush();
        pw.close();
    }

 

脚本宝典总结

以上是脚本宝典为你收集整理的Ajax+servlet练习题全部内容,希望文章能够帮你解决Ajax+servlet练习题所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。