• 使用HttpServlet简单实例


    使用HttpServlet简单实例

    
    package com.kettas.servlet ;
    
    import javax.servlet.* ;
    
    import javax.servlet.http.* ;
    
    import java.io.* ;
    
    public class LoginServlet extends HttpServlet{
    
        @Override 
    
        public void service( HttpServletRequest request , HttpServletResponse response )
    
            throws ServletException , IOException 
    
        {   response.setContentType("text/html; charset=GB2312"); // 注意设置编码的方式
    
            request.setCharacterEncoding("GB2312");
    
            PrintWriter out = response.getWriter();
    
            // 取得客户端提交的数据 
    
            String name = request.getParameter( "userName" ) ;
    
            String pwd = request.getParameter( "password" ) ;
    
            out.println("<html>");
    
            out.println("<body>");
    
            out.println("<h1>");
    
            out.println("Name : " + name + "   " + "Password : " + pwd);
    
            out.println("</h1>");
    
            out.println("</body>");
    
            out.println("</html>");
    
            out.flush();
    
        }
    
    }
    

    配置文件web.xml片段:

    
    <servlet> 
    
        <servlet-name>login</servlet-name>
    
        <servlet-class>com.kettas.servlet.LoginServlet</servlet-class>
    
    </servlet>                                      
    
    <servlet-mapping>       
    
        <servlet-name>login</servlet-name>
    
        <url-pattern>/login</url-pattern>
    
    </servlet-mapping>
  • 相关阅读:
    今日总结
    今日总结
    今日总结
    k8s controller
    深入k8s:Informer使用及其源码分析
    理解 K8S 的设计精髓之 List-Watch机制和Informer模块
    Unix domain socket 简介
    Linux网络编程——端口复用(多个套接字绑定同一个端口)
    DPVS Tutorial
    dpvs route RTF_KNI
  • 原文地址:https://www.cnblogs.com/yuyu666/p/9743885.html
Copyright © 2020-2023  润新知