码迷,mamicode.com
首页 > Web开发 > 详细

使用httpServlet方法开发

时间:2019-06-07 15:32:59      阅读:109      评论:0      收藏:0      [点我收藏+]

标签: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");
    }

}
View Code

相比较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>
View Code

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"));
}

}
View Code

 技术图片

 

使用httpServlet方法开发

标签:world   log   技术   login   one   exce   throw   怎么   ons   

原文地址:https://www.cnblogs.com/helloworld2019/p/10987102.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!