00d1b4c0b088001d160fad3e9d937e41

来自「一个相对比较简单的留言簿!功能还比较齐全!」· 代码 · 共 71 行

TXT
71
字号
package com.pure35.servlet;

import java.io.IOException;

import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pure35.database.MessageDao;

public class UpdateMessage extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 此方法和doGet合二为一 <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 {

		this.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 {

		//得到要修改留言的ID 该id是由用户单击“修改”连接时
		//<a href='UpateMessage?id=message.getId()' >修改</a>得到的
		String mid=request.getParameter("id");
		int id=Integer.parseInt(mid);
		//通过得到的id查询  该留言的详细信息 
		String sql="select * from message where id="+id;
		MessageDao mdao=new MessageDao();
		List messagelist=mdao.queryMessage(sql);
		
		//传递得到的留言信息
		request.setAttribute("updatemessage", messagelist);
		
		//跳转到留言显示页面
		request.getRequestDispatcher("ShowMessage").forward(request, response);
		
		
		
	
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?