当前位置 : 主页 > 编程语言 > c++ >

Servlet工作原理分析

来源:互联网 收集:自由互联 发布时间:2021-07-03
Servlet类 package com.cqupt;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.IOException;import java.io.Pr
Servlet类
package com.cqupt;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 一个简单的Servlet
 * @author hetiantian
 */
public class HelloWorld extends HttpServlet{
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        response.setCharacterEncoding("gb2312");

        PrintWriter out = response.getWriter();
        String name = request.getParameter("username");

        out.println("Your name: " + name);

    }
}
Web.xml配置文件
 

 

    
   
   
    HelloWorld
    
   
    com.cqupt.HelloWorld
    
  

    
   
   
    HelloWorld
    
   
    /HelloWorld
    
  

 
前端页面,一个表单:index.jsp
<%--
  Created by IntelliJ IDEA.
  User: hetiantian
  Date: 2017/9/2
  Time: 13:19
  To change this template use File | Settings | File Templates.
--%>
	<%@ page contentType="text/html;charset=UTF-8" language="java" %>
		

		
			$Title$
		

		
			
 
Your Name:
网友评论