使用httpServlet方法开发
Posted helloworld2019
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用httpServlet方法开发相关的知识,希望对你有一定的参考价值。
使用继承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"));
以上是关于使用httpServlet方法开发的主要内容,如果未能解决你的问题,请参考以下文章
Servlet----------通过 HttpServlet 开发Servlet