📄 viewmythreadaction.java
字号:
package org.redsoft.forum.web;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.redsoft.forum.ForumConstants;import org.redsoft.forum.dao.Account;import org.redsoft.forum.dao.DAOFactory;import org.redsoft.forum.exception.AccountNotFoundException;import org.redsoft.forum.exception.DAOException;import org.redsoft.forum.security.User;import javax.security.auth.Subject;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.IOException;import java.util.Collection;/** * View a collection of thread posted by a specific user * * @author John Liu * @author Charles Huang * @version 1.0 * @version - April, 11, 2002 * */public class ViewMyThreadAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, DAOException, AccountNotFoundException { // Get the current user from session final Subject subject = (Subject)request.getSession().getAttribute(ForumConstants.USER_KEY); final String userId = ( (User)subject.getPrincipals( User.class ).iterator().next() ).getName(); // calculate startIndex int startIndex = 1; // if url is viewMyThreads.go?startIndex=21 String startIndexString = request.getParameter( ForumConstants.START_INDEX_PARAM ); if ( startIndexString != null ) { startIndex = Integer.parseInt( startIndexString ); } // Calculate endIndex int endIndex = startIndex + ForumConstants.MAX_THREADS_PER_PAGE - 1; int myThreadCount = DAOFactory.getInstance().getThreadDAO().findCountByUserId( userId ); // if endIndex is bigger than my thread count, use mythread count as endIndex if ( endIndex > myThreadCount ) { endIndex = myThreadCount; } // if have previous page int previous = startIndex - ForumConstants.MAX_THREADS_PER_PAGE; if ( previous >= 0 ) { request.setAttribute( "previous", new Integer( previous ) ); System.out.println("previous = " + previous); } // if have next page int next = startIndex + ForumConstants.MAX_THREADS_PER_PAGE; if ( next < myThreadCount ) { request.setAttribute( "next", new Integer( next ) ); } final Account account = DAOFactory.getInstance().getAccountDAO().findByUserName( userId ); Collection myThreadList = DAOFactory.getInstance().getThreadDAO().findByUserId(userId, startIndex, endIndex); request.setAttribute(ForumConstants.START_INDEX_PARAM, new Integer( startIndex ) ); request.setAttribute(ForumConstants.END_INDEX_PARAM, new Integer( endIndex ) ); request.setAttribute(ForumConstants.THREAD_COUNT_PARAM, new Integer( myThreadCount ) ); request.setAttribute(ForumConstants.MY_THREAD_PARAM, myThreadList); request.setAttribute(ForumConstants.ACCOUNT, account); // Forward control to the specified success URI return (mapping.findForward("success")); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -