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

📄 saveadminaction.java

📁 基于struct结构的jsp
💻 JAVA
字号:
package com.ntsky.bbs.action;

import java.io.*;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import org.apache.log4j.Logger ;
import org.apache.commons.beanutils.PropertyUtils;

import com.ntsky.xml.XMLPath;
import com.ntsky.xml.XMLReadWrite;
import com.ntsky.bbs.service.Manager;
import com.ntsky.bbs.action.Constant;
import com.ntsky.bbs.service.db.DBManager;
/**
 * <p>Title: Ntsky OpenSource BBS</p>
 * <p>Description:保存安装参数 </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: WWW.FM880.COM</p>
 * @author 姚君林
 * @version 1.0
 */

public class SaveAdminAction extends Action {
    private final static Logger logger = Logger.getLogger(SaveAdminAction.class);
    public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception{

        HttpSession session = httpServletRequest.getSession();

        //判断用户是否是第一次(方便管理员更改密码操作)
        String time = httpServletRequest.getParameter("time");
        String action = httpServletRequest.getParameter("action");
        logger.info("该操作是" + time + "次");

        //获取用户名和密码
        String adName = (String)PropertyUtils.getSimpleProperty(actionForm, "adName");
        logger.info("用户名 :"+adName);
        String adPassWd = (String)PropertyUtils.getSimpleProperty(actionForm, "adPassWd");
        String adLastLoginIp = httpServletRequest.getRemoteAddr();
        logger.info("IP地址 : " + adLastLoginIp);

        Manager manager = new DBManager();
        //安装选项
        if((Constant.TIME).equals(time)){
            //第一次就插入纪录
            if(manager.insAdmin(adName,adPassWd,adLastLoginIp)){
                logger.info("安装论坛失败!要创建的用户 " + adName + " 不是本论坛的注册用户!");
                //该用户不存在返回信息给客户端
                ActionMessages messages = new ActionMessages();
                ActionMessage message = new ActionMessage(
                    "message.setup.error.userNotExist",adName);
                messages.add(ActionMessages.GLOBAL_MESSAGE, message);
                saveMessages(httpServletRequest, messages);
                return (actionMapping.findForward("setup_faile"));
            }

            /**
             * 删除该文件
             */
            String realPath = XMLReadWrite.getInstance().getRealPath(XMLPath.NTSKY_LINK);
            realPath = realPath.substring(0,realPath.indexOf("WEB-INF"));
            logger.info("realPaht = " + realPath);
            File file = new File(realPath+"tiles/setup.jsp");
            if(file.exists()){
                file.delete();
            }
            session.setAttribute(Constant.ADMIN_KEY, adName);
            return (actionMapping.findForward("success"));
        }

        /**
         * 判断用户是否登陆
         */
        if (!manager.isAdminUser(adName, adPassWd)) {
            logger.info("管理员登陆失败!");
            //该用户不存在返回信息给客户端
            ActionMessages messages = new ActionMessages();
            ActionMessage message = new ActionMessage(
                "message.setup.error.adminLoginError", adName);
            messages.add(ActionMessages.GLOBAL_MESSAGE, message);
            saveMessages(httpServletRequest, messages);
            logger.info("输出错误信息返回到登陆页");
            return (actionMapping.findForward("admin_logon"));
        }
        else {
            //设置管理员session
            session.setAttribute(Constant.ADMIN_KEY, adName);
            return (actionMapping.findForward("success"));
        }
    }
}

⌨️ 快捷键说明

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