noticemodifyaction.java

来自「使用hibernate+struts2+spring实现的地址本管理系统」· Java 代码 · 共 51 行

JAVA
51
字号
package nm.user.action;

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

import nm.Notice;
import nm.user.form.NoticeModifyForm;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

/**
 * <strong>InsertNewUserAction </strong> inserts a new user into the database.
 */
public final class NoticeModifyAction extends Action {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		String title = ((NoticeModifyForm) form).getTitle();
		title = new String(title.getBytes("ISO-8859-1"), "GB2312");

		String content = ((NoticeModifyForm) form).getContent();
		content = new String(content.getBytes("ISO-8859-1"), "GB2312");

		ActionErrors errors = new ActionErrors();
		String pageForward = "ToErrorPage";
		try {
			Notice bean = (Notice) (request.getSession()
					.getAttribute("noticeBean"));
			bean.modifyByID(bean.getID(), title, content);
			pageForward = "ToNoticeList";
		} catch (Exception ex) {

			ex.printStackTrace(System.out);

			errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
					"notice.modify.failed"));
			saveMessages(request, errors);

		}
		return (mapping.findForward(pageForward));

	}
}

⌨️ 快捷键说明

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