⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewmythreadaction.java

📁 如题ServletJSP.rar 为网络收集的JSP网站源文件
💻 JAVA
字号:
package org.redsoft.forum.web;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import javax.security.auth.Subject;

import org.apache.struts.action.Action;
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;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.util.MessageResources;
import org.redsoft.forum.dao.ThreadDAO;
import org.redsoft.forum.dao.DAOFactory;
import org.redsoft.forum.ForumConstants;
import org.redsoft.forum.security.User;

/**
 * View a collection of thread posted by a specific user
 *
 * @author John Liu
 * @author Charles Huang
 * @version 1.0
 * @date - April, 11, 2002
 *
 */
public class ViewMyThreadAction extends Action
{
    public ActionForward perform(ActionMapping mapping,
                                    ActionForm form,
                                    HttpServletRequest request,
                                    HttpServletResponse response)
        throws IOException, ServletException {

        final HttpSession session = request.getSession();

        final ActionErrors actionErrors = new ActionErrors();

        // 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();
/*
        // If the user is null which means the user has not loged in,forward it to logon screen
        if( userId == null || userId.length() == 0 ){
			final String url = "/viewMyThreads.go";
			request.setAttribute( ForumConstants.DEST_URL, url );
			return (mapping.findForward("logon"));

		// Else display the user's threads
		}else{
*/
            int pageNo = 1;
    	    try {
    	        pageNo = Integer.parseInt((String)(request.getAttribute(ForumConstants.MY_THREAD_PAGE)));
    	    } catch (final NumberFormatException nfe) {
    	        pageNo = 1;
    	    }

    	    final Collection myThreadList=new Vector();

    	    // put the page number info to the Collection as the first object
    	    myThreadList.add(new Integer(pageNo));

    	    try {
    	        myThreadList.addAll(DAOFactory.getInstance().getThreadDAO().findByUserId(userId));

    	    } catch (final SQLException se) {
    	        se.printStackTrace();
    	        return (mapping.findForward("error"));
    	    }

    	    // Remove the obsolete form bean
    	    if (mapping.getAttribute() != null) {
    	        if ("request".equals(mapping.getScope()))
    	            request.removeAttribute(mapping.getAttribute());
    	        else
    	            session.removeAttribute(mapping.getAttribute());
    	    }

        	request.setAttribute(ForumConstants.MY_THREAD_PARAM,myThreadList);

        	// Forward control to the specified success URI
        	return (mapping.findForward("success"));
/*
        }
*/
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -