标签:world log 技术 login one exce throw 怎么 ons
使用继承HttpServlet方法开发
显示HeeloWorld以及当前日期
默认Doget方式提交
package com.wangzhi.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class MyServlet extends HttpServlet { protected void doGet(HttpServletRequest res, HttpServletResponse resp) throws ServletException, java.io.IOException { resp.getWriter().println("I‘m a student"); } protected void doPost(HttpServletRequest res, HttpServletResponse resp) throws ServletException, java.io.IOException { resp.getWriter().println("I‘m a senior student"); } }
相比较post而言安全性低
怎么使用Dopost方式?
login.html
<html> <body> <form action="/web/MyServlet" method="post"> <input type="String" name="username" value="username"/> <input type="submit" value="login"/> </form> </body> </html>
MyServlet.java
package com.wangzhi.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class MyServlet extends HttpServlet { protected void doGet(HttpServletRequest res,HttpServletResponse resp) throws ServletException, java.io.IOException { resp.getWriter().println("this doGet"); } protected void doPost(HttpServletRequest res,HttpServletResponse resp) throws ServletException, java.io.IOException { resp.getWriter().println("This is doPost"+res.getParameter("username")); } }
标签:world log 技术 login one exce throw 怎么 ons
原文地址:https://www.cnblogs.com/helloworld2019/p/10987102.html