package com.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class chat extends HttpServlet {
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
doPost(request,response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter();
HttpSession session=request.getSession();
String action=request.getParameter("action");
if(action!=null&&action.equals("login")){
String name=request.getParameter("name");
session.setAttribute("name",name);
request.getRequestDispatcher("../main.htm").forward(request,response);
}
if(action!=null&&action.equals("send")){
String name=session.getAttribute("name").toString();
String object=request.getParameter("object");
String content=request.getParameter("content");
String all="<a href='#'>"+name+"</a>"+"对"+"<a href='#'>"+object+"</a>"+"说:"+content+"<br>";
System.out.println(all);
ServletContext application=request.getSession().getServletContext();
if(application.getAttribute("content")==null){
application.setAttribute("content",all);
}
else{
all=all+application.getAttribute("content");
application.setAttribute("content",all);
}
request.getRequestDispatcher("../send.jsp?object="+object+"").forward(request,response);
//System.out.print("hello");
}
if(action!=null&&action.equals("out")){
session.invalidate();
out.print("<script>alert('asdasdasd');parent.location.href='../index.htm';</script>");
}
out.flush();
out.close();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
聊天室.rar (21个子文件)
聊天室
chatroom.rar 12KB
chatroom
src
com
filter
Filter.java 1KB
listener
listener.java 2KB
action
chat.java 3KB
.classpath 340B
.mymetadata 297B
.settings
org.eclipse.core.resources.prefs 204B
.myeclipse
.project 1KB
WebRoot
META-INF
MANIFEST.MF 39B
main.htm 614B
top.htm 307B
index.htm 1010B
login_do.jsp 499B
send.jsp 1KB
left.jsp 517B
df.jsp 361B
right.jsp 424B
WEB-INF
classes
com
filter
Filter.class 2KB
listener
listener.class 3KB
action
chat.class 3KB
lib
web.xml 1KB
共 21 条
- 1
资源评论
hqs19821108
- 粉丝: 51
- 资源: 211
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功