📄 editeventaction.java
字号:
package com.wrox.tourism.actions;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import com.wrox.tourism.db.util.ConnectionPool;
import com.wrox.tourism.db.EventDAO;
import com.wrox.tourism.entity.Event;
public class EditEventAction extends Action {
private ConnectionPool pool;
public EditEventAction() {
pool = ConnectionPool.getInstance();
}
public ActionForward perform(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException {
Connection con = null;
ActionErrors errors = new ActionErrors();
try {
con = pool.getConnection();
int eventId = Integer.parseInt(
request.getParameter("eventId"));
EventDAO eventDAO = new EventDAO(con);
Event event = eventDAO.findByPrimaryKey(eventId);
request.setAttribute(BeanNames.EVENT_FORM,event);
return mapping.findForward("success");
} catch (SQLException e) {
e.printStackTrace();
ActionError error = new ActionError("error.unexpected");
errors.add(ActionErrors.GLOBAL_ERROR,error);
} catch (Throwable e) {
e.printStackTrace();
ActionError error = new ActionError(e.getMessage());
errors.add(ActionErrors.GLOBAL_ERROR,error);
} finally {
try {
if (con != null)
con.close();
} catch (SQLException e) {
throw new RuntimeException(e.getMessage());
}
}
saveErrors(request,errors);
return new ActionForward(mapping.getInput());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -