ServletContext练习
来源:互联网 发布:淘宝怎么看下单顺序 编辑:程序博客网 时间:2024/05/12 11:22
import java.io.IOException;import java.io.PrintWriter;import java.util.*;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class SendMsgServlet extends HttpServlet{private ServletContext application;public void init(){System.out.println("init");//获取上下文application = this.getServletContext();List<String> msglist = new ArrayList<String>();application.setAttribute("MsgList", msglist);}public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException{System.out.println("doGet");String ip = req.getRemoteAddr();//获取ipString msg = req.getParameter("msg");//发送的消息String face = req.getParameter("face");//表情图片String context = ip+" say:"+msg+"<img src='faces/"+face+".gif'>";List<String> msgs = (List<String>)application.getAttribute("MsgList");msgs.add(context);PrintWriter pw = resp.getWriter();pw.write("<html>");pw.write("<body>");pw.write(context);pw.write("<div class=\"send\">"+"<form action=\"sendMsg\" method=\"post\">"+"<input type=\"text\" id=\"sendText\" name=\"msg\"/>"+"<select name=\"face\" class=\"face\">"+"<option value=\"1\">suprise</option>"+"<option value=\"2\">embarase</option>"+"<option value=\"3\">sex</option>"+"</select>"+"<input type=\"submit\" value=\"submit\" id=\"submit\"/>"+"</form>"+"</div>");pw.write("</body>");pw.write("</html>");}protected void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {doGet(req,resp);System.out.println("doPost");}}
0 0
- ServletContext练习
- ServletContext
- ServletContext
- servletcontext
- servletContext
- servletContext
- servletcontext
- ServletContext
- ServletContext
- servletContext
- ServletContext
- ServletContext
- servletContext
- ServletContext
- servletContext
- ServletContext
- servletContext
- ServletContext
- Semantic matching & Semantic correlation matching
- 《深入理解java虚拟机》之垃圾回收
- opencv7-ml之KNN
- hibernate4.3.5需要的jar包
- 【Android】读《第一行代码》笔记总结
- ServletContext练习
- socket是什么
- Swift 细小知识点汇集
- 第4周项目3-单链表应用(3)
- 和大于S的最小子数组
- 《C++primer(第五版)》学习之路-第十二章:动态内存
- Android短信验证码自动填写的实现
- 工具链无效。新 App 和 App 更新必须使用公共(正式)版 Xcode 6 或更高版本以及 iOS 8 SDK 或更高版本来构建。请勿提交 Beta 版软件构建的 App。
- 剑指Offer-3-二维数组中的查找