JavaWeb后台從input表單獲取文本值的兩種方式


 JavaWeb后台從input表單獲取文本值的兩種方式
####   index.html
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    
    <input type="text"  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?name='+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"/>
        <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);

    }
    }
 

 
  

  

 
 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM