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

📄 login.java

📁 JAVA邮件系统
💻 JAVA
字号:
/* 
 *
 */

import java.io.*;
import java.text.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 * 
 *
 * @author Chen Xin Wu
 */

public class Login extends HttpServlet {


    public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
		doGet(request,response);
	}
	public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
		try{
			HtmlOut htmlOut = new HtmlOut (response);
				

			// 得到名字和口令
			String name,pass,action;

			//one way , user are login by name and pass;
			name = CommonMethods.getParameterValue (request,"Name");
			pass = CommonMethods.getParameterValue (request,"Password");
			action = CommonMethods.getParameterValue (request,"action");
			if(name!=null&&pass!=null){
				htmlOut.addCookie ("username",name);
				htmlOut.addCookie ("password",pass);
			}
			else{//other we get it by cookie;
				name = CommonMethods.GetUserName(request);
				pass = CommonMethods.GetUserPass(request);
			}
				
				
			Person person = new Person();
			person.setName (name);
			person.setPassword ( pass );
			
			if( (action!=null&&action.compareTo("reLog")==0)||person.getName ()==null )
			{
				htmlOut.setRedirect ("MakeLogin");
				htmlOut.outHtml();
				return;
			}
			if(!person.checkPassword(pass)){
				htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
									"请输入正确的用户名,密码!(因为系统更新,也许您需要重新注册您的用户)","Login?action=reLog");
				htmlOut.outHtml();
				return;
			}
			
			int nPage=0;
			DBOperater DB=new DBOperater ("userchannel");;
			String sPage = request.getParameter("p");
			if( sPage!=null )
				nPage=Integer.valueOf(sPage).intValue ();
			else{
				String channelname = request.getParameter("channel");
				if( channelname!=null ){
					ResultSet rs = DB.executeQuery ("select pagenumber from userchannel where username = '"
													+CommonMethods.DealWithSQLParameter (person.getName ())+"'"
													+" and channelid='"
													+CommonMethods.DealWithSQLParameter (channelname)+"'");
					if(rs!=null){
						try{
							if( rs.next () )
								nPage = rs.getInt (1);
						}
						catch(Exception e){
						}
					}
				}
			}
				
			//check all page number;
			int nAllPage=1;
				
			ResultSet rs = DB.executeQuery ("select pagenum from person where username = '"
											+CommonMethods.DealWithSQLParameter (person.getName ())
											+"'");
			if(rs!=null){
				try{
					if( rs.next () )
						nAllPage = rs.getInt (1);
				}
				catch(Exception e){
				}
			}
			int nPage2 = 1;
			rs = DB.executeQuery ("select pagenumber from userchannel where username = '"
								  +CommonMethods.DealWithSQLParameter (person.getName ())
								  +"' ORDER BY pagenumber DESC");
			if(rs!=null){
				try{
					if( rs.next () )
						nPage2  = rs.getInt (1)+1;
				}
				catch(Exception e){
				}
			}
			if(nPage2 > nAllPage){
				nAllPage = nPage2;
				DB.executeUpdate("update person set pagenum = "+nAllPage +"where ( username='"
						+ CommonMethods.DealWithSQLParameter (person.getName()) + "')");
			}
			DB.close ();
			//if the page is invalid , set it the valid data;
			if( nPage < 0 )
				nPage = nAllPage-1;
			if( nPage>nAllPage-1 )
				nPage = nAllPage - 1 ;
				
			//set page cookie;
				
			TemplateList tempList = CommonMethods.getLoginTemplate ();
			ReplaceEngineLogin re = new ReplaceEngineLogin();
			re.setPage (nPage);
			if(tempList!=null){
				if( !re.replace(tempList,person,htmlOut) ){
					htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE  ,
										"","页面生成失败!","");
				}
			}
			else{
				htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE  ,"","模板文件错误!","");
			}
			htmlOut.outHtml();
		}catch(Exception e){
		}
    }
}



⌨️ 快捷键说明

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