Servlet中的doGet和doPost我開(kāi)發(fā)了一個(gè)HTML頁(yè)面,它向servlet發(fā)送信息。在servlet中,我使用以下方法doGet()和doPost():public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException {
String id = req.getParameter("realname");
String password = req.getParameter("mypassword");}public void doPost(HttpServletRequest req,
HttpServletResponse res)throws ServletException, IOException {
String id = req.getParameter("realname");
String password = req.getParameter("mypassword");}在調(diào)用servlet的html頁(yè)面代碼中,如下所示:<form action="identification" method="post" enctype="multipart/form-data">
User Name: <input type="text" name="realname">
Password: <input type="password" name="mypassword">
<input type="submit" value="Identification"></form>當(dāng)我用method = "get"在servlet中,我得到id和密碼的值,但是當(dāng)使用method = "post",id和密碼設(shè)置為null..為什么我不知道這個(gè)案子的價(jià)值呢?我想知道的另一件事是如何使用servlet生成或驗(yàn)證的數(shù)據(jù)。例如,如果上面顯示的servlet對(duì)用戶進(jìn)行身份驗(yàn)證,我希望在我的HTML頁(yè)面中打印用戶id。我應(yīng)該能夠發(fā)送字符串‘id’作為響應(yīng),并在我的HTML頁(yè)面中使用這個(gè)信息。有可能嗎?
Servlet中的doGet和doPost
BIG陽(yáng)
2019-06-10 21:01:47