📄 addguestbookaction.java
字号:
/*
* @author : Neelesh
* @Version : 1.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the File : AddGuestbookAction.java
* Creation/Modification History :
*
* Neelesh 04-Apr-2003 Created
*
*/
package oracle.otnsamples.vsm.actions.mall;
//Servlet and IO API
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import oracle.otnsamples.util.MessageCache;
import oracle.otnsamples.util.ServiceLocator;
import oracle.otnsamples.vsm.actions.forms.GuestbookForm;
import oracle.otnsamples.vsm.services.MallNavigation;
import oracle.otnsamples.vsm.services.MallNavigationHome;
import oracle.otnsamples.vsm.services.ServiceException;
import oracle.otnsamples.vsm.services.data.Guestbook;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
* The action class adds an entry to the guestbook.
*
* @author Neelesh
* @version 1.0
*/
public class AddGuestbookAction extends HomePageAction {
/**
* This is the action called from the Struts framework to add an entry to the
* guestbook.
*
* @param <b>mapping</b> The ActionMapping used to select this instance.
* @param <b>form</b> The optional ActionForm bean for this request.
* @param <b>request</b> The HTTP Request we are processing.
* @param <b>response</b> The HTTP Response we are processing.
*
* @return <b>ActionForward</b> The control forward information
*
* @throws <b>IOException</b>
* @throws <b>ServletException</b>
*/
public ActionForward execute(
ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
MallNavigationHome navigationHome =
(MallNavigationHome) ServiceLocator.getLocator().getService("MallNavigation");
MallNavigation navigation = null;
try {
navigation = navigationHome.create();
GuestbookForm guestbookForm = (GuestbookForm) form;
String langID = getLocale(request).getLanguage();
// create a value object for guestbook entry
Guestbook guestbookEntry =
new Guestbook(
null, guestbookForm.getUserName(),
guestbookForm.getEmail(), guestbookForm.getRating(),
guestbookForm.getComments(), null, langID);
// add the entry to the application
navigation.addGuestbookEntry(guestbookEntry);
// Save the key for success message in the session
request.getSession().setAttribute("messageKey","message.guestbookadd");
} catch(ServiceException ex) {
// handle errors
servlet.log("GuestbookError", ex);
ActionErrors errors = new ActionErrors();
errors.add(
"GuestbookError",
new ActionError(
"error.guestbookaction",
MessageCache.getMessage(
ex.getMessageCode(),
getLocale(request))));
saveErrors(request, errors);
return mapping.findForward("failure");
} catch(Exception ex) {
//log errors
servlet.log("GuestbookError", ex);
// save error message
ActionErrors errors = new ActionErrors();
errors.add("HomePageError", new ActionError("error.guestbookaction"));
saveErrors(request, errors);
// forward to error page
return mapping.findForward("failure");
} finally {
// remove SLSB instance
if(navigation != null) {
try {
navigation.remove();
} catch(Exception ex) {
}
}
}
// since the control comes to main page, data needed by that page
// is provided in the exexute method of HomePageAction
super.execute(mapping, form, request, response);
return mapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -