首页 > 编程语言 > 详细

JavaWeb后台从input表单获取文本值的两种方式

时间:2018-09-03 22:50:05      阅读:245      评论:0      收藏:0      [点我收藏+]
 JavaWeb后台从input表单获取文本值的两种方式
####   index.html
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    
    <input type="text" name="name" id="cid"/>
    <button id="btn">提交</button>
    <script src="admin/js/jquery.min.js"></script>
    <script>
    
       $("#btn").click(function () {
            //获取input表单文本框的值
           var name=$(‘#cid‘).val();
            $(window).attr(‘location‘,‘/QueryOneStudent?sid=‘+name+‘‘);
        });
    </script>
    </body>
    </html>

####index2.html
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <form action="/QueryOneStudent">
        <input type="text" name="name" id="cid"/>
        <input type="submit" value="提交"/>
    </form>
    </body>
    </html>

####QueryOneStudent.java文件
    @WebServlet("/QueryOneStudent")
    public class QueryOneStudent extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("QueryOneStudent");

        String name = req.getParameter("name");
        System.out.println(name);

    }
    }
 

 
  

  

 
 

  

JavaWeb后台从input表单获取文本值的两种方式

原文:https://www.cnblogs.com/my12/p/9581577.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!