zoukankan      html  css  js  c++  java
  • servlet 将输入内容通过拼接页面的方式显示出来

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- charset="utf-8" 页面编码 -->
    
    <title>ReturnName</title>
    </head>
    <body>
    	<form action="ReturnNameServlet" method="post">
    		<input type="text" name="textname"> 
    		<input type="submit" value="提交">
    	</form>
    </body>
    </html>
    

    returnname.html

    package controller;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    /**
     * Servlet implementation class ReturnNameServlet
     */
    @WebServlet("/ReturnNameServlet")
    public class ReturnNameServlet extends HttpServlet {
    	private static final long serialVersionUID = 1L;
    
        /**
         * Default constructor. 
         */
        public ReturnNameServlet() {
            // TODO Auto-generated constructor stub
        }
    
    	/**
    	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		// TODO Auto-generated method stub
    	}
    
    	/**
    	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		// TODO Auto-generated method stub
    		
    		request.setCharacterEncoding("utf-8");
    		response.setCharacterEncoding("utf-8");
    		//设置编码字符集
    		
    		
    		String username=request.getParameter("textname");
    		response.setContentType("text/html");
    		PrintWriter out = response.getWriter();
    		out.print("<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>");
    		out.print("<body>submitname is ");
    		out.print(username);
    		out.print("</body>");
    		out.flush();
    		out.close();
    	}
    
    }
    

     ReturnNameServlet.java

  • 相关阅读:
    通过递归展示树状结构
    Description Resource Path Location Type Failure to transfer org.apache.maven.plugins:maven-surefire-
    Entity与Entity之间的相互转化
    java 记录数据持续变化时间
    Springmvc 异常处理
    Spring Validation 验证
    Jmeter的操作流程
    Python基础字符串前加u,r,b,f含义
    linux连接Windows系统之项目连接
    Jmeter 连接远程测压__(负载测试)
  • 原文地址:https://www.cnblogs.com/tianhao/p/4020735.html
Copyright © 2011-2022 走看看