Servlet与表单

input.html





InputServlet


    
输入内容:

InputServlet.java

package im.weitang;

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

public class InputServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charSet=UTF-8");

        String info = request.getParameter("info");
        PrintWriter out = response.getWriter();
        out.println("");
        out.println("");
        out.println("InputServlet");
        out.println("");
        out.println("");
        out.println("

" + info + "

"); out.println(""); out.println(""); out.close(); } }

修改web.xml,添加下面的代码


    InputServlet
    im.weitang.InputServlet


    InputServlet
    /InputServlet

你可能感兴趣的:(Servlet与表单)