model package com.message.user;public class User {private String userName;private String userMessage;private String userLeaveMessageTime;public User(){}public String getUserName() {return userName;}public void setUserName(String userName) {
package com.message.user; public class User { private String userName; private String userMessage; private String userLeaveMessageTime; public User(){} public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getUserMessage() { return userMessage; } public void setUserMessage(String userMessage) { this.userMessage = userMessage; } public String getUserLeaveMessageTime() { return userLeaveMessageTime; } public void setUserLeaveMessageTime(String userLeaveMessageTime) { this.userLeaveMessageTime = userLeaveMessageTime; } public User(String userName, String userMessage, String userLeaveMessageTime) { super(); this.userName = userName; this.userMessage = userMessage; this.userLeaveMessageTime = userLeaveMessageTime; } }controller
package com.message.user; import java.io.IOException; import java.util.*; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet(name="MessageServlet", urlPatterns="/messageservlet") public class MessageServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ User user=new User(); user.setUserMessage(request.getParameter("usermessage")); user.setUserName(request.getParameter("username")); user.setUserLeaveMessageTime(new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss") .format(new Date()).toString()); Listview0userList=(List )request.getSession().getAttribute("userlist"); if(userList==null) { userList=new ArrayList (); } userList.add(user); request.getSession().setAttribute("userlist", userList); request.getRequestDispatcher("Message.jsp").forward(request,response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ doGet(request,response); } }
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" language="java"%>view1Insert title here
<%@ page language="java" contentType="text/html; UTF-8" pageEncoding="UTF-8"%> <%@page import="java.util.*"%> <%@ page import="com.message.user.User" %>Insert title here 继续留言
<% @SuppressWarnings("unchecked") ArrayListuserList=(ArrayList )session.getAttribute("userlist"); for(int i=0;i "+userList.get(i).getUserLeaveMessageTime()+""+""+"" +userList.get(i).getUserName()+":" +userList.get(i).getUserMessage()+""+""+""); %>