📄 deleteresponseaction.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -