首页 > 代码库 > servlet 将输入内容通过拼接页面的方式显示出来
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="http://www.mamicode.com/提交"> </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
servlet 将输入内容通过拼接页面的方式显示出来
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。