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

📄 addbbsaction.java

📁 使用J2EE Struts开发的房地产信息咨询系统
💻 JAVA
字号:
/**
 * AddBBSAction.java
 * 论坛添加新帖
 * @author usr
 */

package building;

import javax.sql.*;
import javax.servlet.ServletContext;
import javax.servlet.http.*;
import org.apache.struts.action.*;

public final class AddBBSAction extends Action
{
	public ActionForward execute(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response)
	throws Exception
	{
		DynaActionForm BBSForm = (DynaActionForm)form;
		
		String title = (String)BBSForm.get("title");
		String contents = (String)BBSForm.get("contents");
		
		//
		title = CharSet.GBK_ISO(title);
		contents = CharSet.GBK_ISO(contents);
		
		//
		String PageForward = null;
		ActionMessages errors = new ActionMessages();
				
		//
		HttpSession session = request.getSession(true);
		Users user = (Users)session.getAttribute(Constants.USER_INFO_KEY);
		
		//
		if ( user == null )
		{
			//用户未登录
			errors.add(ActionMessages.GLOBAL_MESSAGE,
					new ActionMessage("errors.userNotLogin"));
			if ( !errors.isEmpty() )
			{
				saveErrors(request,errors);
			}//End of if
			
			return(mapping.findForward("toWrong"));
		}
		//
		BBS bbs = new BBS();
		bbs.setUserId(user.getId());
		bbs.setTitle(title);
		bbs.setContents(contents);
		bbs.setSubtime(ChinaTime.getTime());
		
		//
		ServletContext context = servlet.getServletContext();
		DataSource dataSource = (DataSource)context.getAttribute(Constants.DATASOURCE_KEY);
		DB db = new DB(dataSource);
		
		
		
		if ( (user == null) || (Users.ifExist(db,user.getUserName())) )
		{
			//用户已经登录
			if ( bbs.addNewBBS(db) )
			{
				//添加成功
				PageForward = "toAddBBSOK";
			}//End of if
			else
			{
				//添加失败
				errors.add(ActionMessages.GLOBAL_MESSAGE,
						new ActionMessage("errors.addBBSFail"));
				if ( !errors.isEmpty() )
				{
					saveErrors(request,errors);
				}//End of if
				
				PageForward = "toWrong";
			}//End of else
		}//End of if
		else
		{
			//用户未登录
			errors.add(ActionMessages.GLOBAL_MESSAGE,
					new ActionMessage("errors.userNotLogin"));
			if ( !errors.isEmpty() )
			{
				saveErrors(request,errors);
			}//End of if
			
			PageForward = "toWrong";
		}//End of else
		
		
		db.close();
		
		return(mapping.findForward(PageForward));
	}//End of execute
	
}//End of class AddBBSAction

⌨️ 快捷键说明

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