📄 entriesfindbyprimarykeyaction.java
字号:
package org.helpsoft.blog.struts.actions;
import org.apache.struts.*;
import org.apache.struts.action.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.*;
import java.math.*;
import org.helpsoft.blog.dao.*;
import org.helpsoft.blog.dto.*;
import org.helpsoft.blog.factory.*;
import org.helpsoft.blog.struts.forms.*;
public class EntriesFindByPrimaryKeyAction extends Action
{
/**
* Method 'execute'
*
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{
try {
// parse parameters
int _entryid = Integer.parseInt( request.getParameter("entryid") );
// create the DAO class
EntriesDao dao = EntriesDaoFactory.create();
// execute the finder
Entries dto = dao.findByPrimaryKey(_entryid);
// check that we have found a row
if (dto == null) {
throw new RuntimeException( "Finder did not return any data" );
}
// populate a struts form
EntriesForm entriesForm = new EntriesForm();
entriesForm.setCrudMethod( request.getParameter("crudMethod") );
entriesForm.setEntryid(String.valueOf( dto.getEntryid() ));
entriesForm.setName(dto.getName());
entriesForm.setAuthor(dto.getAuthor());
entriesForm.setDate(dto.getDate());
entriesForm.setContent(dto.getContent());
// store the results
request.getSession().setAttribute( "Entries", entriesForm );
return mapping.findForward( request.getParameter("crudMethod") );
}
catch (Exception e) {
e.printStackTrace();
ActionErrors _errors = new ActionErrors();
_errors.add( ActionErrors.GLOBAL_ERROR, new ActionError("internal.error", e.getClass().getName() + ": " + e.getMessage() ) );
saveErrors( request, _errors );
return mapping.findForward( "failure" );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -