当前位置: 技术问答>java相关
关于cookie和调用同一页面得问题!
来源: 互联网 发布时间:2015-09-02
本文导语: 怎么样知道我是第一次调用这个页面还是第几次调用这个页面,用cookie怎么写,或者用其他方法怎么写?谢谢!在线等待!!! | String action = (String)request.getParameter("action") ; if ( action != null && a...
怎么样知道我是第一次调用这个页面还是第几次调用这个页面,用cookie怎么写,或者用其他方法怎么写?谢谢!在线等待!!!
|
String action = (String)request.getParameter("action") ;
if ( action != null && action.equals("userlogin") )
{
String timeZone = (String)request.getParameter("timeZone") ;
String userName = (String)request.getParameter("userName") ;
Cookie cookie2=new Cookie("USERNAME", userName);
Cookie cookie3=new Cookie("TIMEZONE", timeZone);
cookie2.setMaxAge(365*24*60*60);
cookie3.setMaxAge(365*24*60*60);
response.addCookie(cookie2);
response.addCookie(cookie3);
Connection conn = MyDB.getConnection();
session.setAttribute("THE_PARTNERNO","11");
session.setAttribute("THE_TIMEZONE",timeZone);
int partnerNo = 11 ;
session.setAttribute("THE_FUNCAREA","COMPANY");
String password = (String)request.getParameter("userPassword");
String sql = "select u.user_no,p.password from users u,user_passwd p where u.loginName='"+MyDB.toSQLStr(userName)+"' and u.partner_no="+ partnerNo+
" and p.user_no=u.user_no" ;
String[][] data = MyDB.fetchStrData(conn,sql) ;
if ( data ==null || !data[0][1].equals(password) )
{
out.println("alert('用户不存在或者口令不对');parent.document.form0.userName.focus();");
return;
}
int userNo = Integer.parseInt(data[0][0]) ;
String helpedName = (String)request.getParameter("helpedName");
if (helpedName != null && helpedName.trim().length() != 0 )
{
sql = "select user_no from users where loginName='"+MyDB.toSQLStr(helpedName)+"' and partner_no='"+ partnerNo+"'" ;
data = MyDB.fetchStrData(conn, sql );
if( data == null)
{
out.println("alert('该被帮助者不存在');parent.document.form0.helpedName.focus();");
return;
}
int helpedNo = Integer.parseInt(data[0][0]) ;
sql = "select func_no from helper_right where user_no="+helpedNo +" and helpedby="+userNo +" and expireDate >= getDate()" ;
data = MyDB.fetchStrData(conn,sql );
if ( data == null )
{
out.println("alert('你无权帮助"+helpedName+"');parent.document.form0.helpedName.focus();");
return;
}
session.setAttribute("THE_USERNO",""+helpedNo );
session.setAttribute("THE_HELPEDBY",""+userNo);
}
else
{
sql = "select func_no from rights where user_no="+userNo ;
data = MyDB.fetchStrData(conn,sql );
if ( data == null )
{
// out.println("alert('你无权访问系统');parent.document.form0.userName.focus();");
// return;
}
session.setAttribute("THE_USERNO",""+userNo );
session.setAttribute("THE_HELPEDBY",null);
}
if ( data == null ) session.setAttribute("THE_RIGHTS",null );
else
{
int rows = data.length;
int[] rights = new int[rows];
for(int i = 0 ;i =1) hour = hour + 12;
String today = sYEAR+"年"+sMonth+"月"+sDay+"日"+hour+"时"+MINUTE+"分";
String userName="",timeZone="8" ;
Cookie cookies[]=request.getCookies();
int j = (cookies==null )?0:cookies.length ;
for ( int i = 0 ; i
用如下代码来判断次数:
String refrenceTimes = request.getParameter("refrenceTimes");
if(refrenceTimes == null)
{
refrenceTimes = "1";
}
else
{
refrenceTimes = Integer.toString(Integer.parseInt(refrenceTimes))+ 1);
}
采用本页提交给本页可以知道被引用的次数。
如果要看本页面被其他页面引用的次数,可采用类似的做法。只要引用一次,改变一次该参数就行了。
if ( action != null && action.equals("userlogin") )
{
String timeZone = (String)request.getParameter("timeZone") ;
String userName = (String)request.getParameter("userName") ;
Cookie cookie2=new Cookie("USERNAME", userName);
Cookie cookie3=new Cookie("TIMEZONE", timeZone);
cookie2.setMaxAge(365*24*60*60);
cookie3.setMaxAge(365*24*60*60);
response.addCookie(cookie2);
response.addCookie(cookie3);
Connection conn = MyDB.getConnection();
session.setAttribute("THE_PARTNERNO","11");
session.setAttribute("THE_TIMEZONE",timeZone);
int partnerNo = 11 ;
session.setAttribute("THE_FUNCAREA","COMPANY");
String password = (String)request.getParameter("userPassword");
String sql = "select u.user_no,p.password from users u,user_passwd p where u.loginName='"+MyDB.toSQLStr(userName)+"' and u.partner_no="+ partnerNo+
" and p.user_no=u.user_no" ;
String[][] data = MyDB.fetchStrData(conn,sql) ;
if ( data ==null || !data[0][1].equals(password) )
{
out.println("alert('用户不存在或者口令不对');parent.document.form0.userName.focus();");
return;
}
int userNo = Integer.parseInt(data[0][0]) ;
String helpedName = (String)request.getParameter("helpedName");
if (helpedName != null && helpedName.trim().length() != 0 )
{
sql = "select user_no from users where loginName='"+MyDB.toSQLStr(helpedName)+"' and partner_no='"+ partnerNo+"'" ;
data = MyDB.fetchStrData(conn, sql );
if( data == null)
{
out.println("alert('该被帮助者不存在');parent.document.form0.helpedName.focus();");
return;
}
int helpedNo = Integer.parseInt(data[0][0]) ;
sql = "select func_no from helper_right where user_no="+helpedNo +" and helpedby="+userNo +" and expireDate >= getDate()" ;
data = MyDB.fetchStrData(conn,sql );
if ( data == null )
{
out.println("alert('你无权帮助"+helpedName+"');parent.document.form0.helpedName.focus();");
return;
}
session.setAttribute("THE_USERNO",""+helpedNo );
session.setAttribute("THE_HELPEDBY",""+userNo);
}
else
{
sql = "select func_no from rights where user_no="+userNo ;
data = MyDB.fetchStrData(conn,sql );
if ( data == null )
{
// out.println("alert('你无权访问系统');parent.document.form0.userName.focus();");
// return;
}
session.setAttribute("THE_USERNO",""+userNo );
session.setAttribute("THE_HELPEDBY",null);
}
if ( data == null ) session.setAttribute("THE_RIGHTS",null );
else
{
int rows = data.length;
int[] rights = new int[rows];
for(int i = 0 ;i =1) hour = hour + 12;
String today = sYEAR+"年"+sMonth+"月"+sDay+"日"+hour+"时"+MINUTE+"分";
String userName="",timeZone="8" ;
Cookie cookies[]=request.getCookies();
int j = (cookies==null )?0:cookies.length ;
for ( int i = 0 ; i
用如下代码来判断次数:
String refrenceTimes = request.getParameter("refrenceTimes");
if(refrenceTimes == null)
{
refrenceTimes = "1";
}
else
{
refrenceTimes = Integer.toString(Integer.parseInt(refrenceTimes))+ 1);
}
采用本页提交给本页可以知道被引用的次数。
如果要看本页面被其他页面引用的次数,可采用类似的做法。只要引用一次,改变一次该参数就行了。