deleteresponseaction.java

来自「JAVA Servlet2.3外文书籍源码」· Java 代码 · 共 43 行

JAVA
43
字号
package forum;

import javax.servlet.http.*;

/**
 * Represents the logic behind deleting a response from a topic.This action
 * is responsible for looking up the appropriate Topic and Response instances
 * and checking whether the currently logged in user is the original author. If
 * this is the case, the response is deleted.
 *
 * @author    Simon Brown
 */
public class DeleteResponseAction extends Action {

  /**
   * Peforms the processing associated with this action.
   *
   * @param request     the HttpServletRequest instance
   * @param response    the HttpServletResponse instance
   * @return  the name of the next view
   */
  public String process(HttpServletRequest request, HttpServletResponse response) {

    System.out.println("DeleteResponseAction : Processing request");

    int topicId = Integer.parseInt(request.getParameter("topic"));
    int responseId = Integer.parseInt(request.getParameter("response"));

    User user = (User)request.getSession().getAttribute("user");

    Topic topic = Topics.getTopic(topicId);
    Response res = topic.getResponse(responseId);

    // is the user the author of the response?
    if (res.getUser().equals(user)) {
      // yes, so delete it
      topic.remove(res);
    }

    return "/controller/ViewTopic?id=" + topicId;
  }

}

⌨️ 快捷键说明

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