📄 musiclistaction.java
字号:
package dummies.struts.music;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
/**
* @author Mike Robinson
*
*/
public class MusicListAction extends Action
{
Log log = LogFactory.getLog(MusicListAction.class); // commons logging reference
/**
* Handles request from user
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
*/
public ActionForward execute( ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
// deterine the action. choices should be null, add, or logoff
String action = (String)((DynaActionForm)form).get("action");
if((action == null)|(action.equals("")))
{
// get the session object
HttpSession session = request.getSession();
// get the user object
UserDTO user = (UserDTO)session.getAttribute("user");
// create a new LoginBean passing the datasource
MusicListBean mlb = new MusicListBean(getDataSource(request, "musiccollection"));
// get the music records for the user
Collection ml = mlb.getMusic(user);
// save MusicDTO collection in session
session.setAttribute("musiclist",ml);
}
else if (action.equalsIgnoreCase("add")) // add a new album
{
//((DynaActionForm)form).set("action","");
//return new ActionForward("/album.do",false);
return (mapping.findForward("newalbum"));
}
else if (action.equalsIgnoreCase("logoff")) // logoff
{
//return new ActionForward("logoff.do",true);
return (mapping.findForward("logoff"));
}
return (mapping.findForward("success"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -