首先,我們得明白用戶登錄使用什么登陸的,即用戶在線的原理。這只是將用戶的對象存放在了session中而已,然后再frame中進行調用,其他特定頁面也進行直接引用就行。那么實現“擠下來”的功能就是讓新生成的session有效,讓原來存放用戶的session失效就行。到此,大體思路已經有了。那怎么實梁鉛現呢?
創新互聯建站是一家集網站建設,龍圩企業網站建設,龍圩品牌網站建設,網站定制,龍圩網站建設報價,網絡營銷,網絡優化,龍圩網站推廣為一體的創新建站企業,幫助傳統企業提升企業形象加強企業競爭力。可充分滿足這一群體相比中小企業更為豐富、高端、多元的互聯網需求。同時我們時刻保持專業、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們為更多的企業打造出實用型網站。
想要知道怎么實現,就必須要明白session存放用戶對象的過程了。在用戶登錄之后,我們可以得到用戶的對象user,而存放到session中需要執行session.setAttribute(key,value); 我們將用橡塌好戶的userId或是其他的唯一標識存為key,將用戶對象存為值。這樣就能隨時隨地調用唯一用戶了。user存放的問題解決了,那相同 登錄 時session廢除的問題呢?
?
這個其實也不難,我們可以更具session的特性一樣,用map進行存貯,將用戶的標識存為key,而將其所對應的session存為value,那么當重復用戶登錄時,只需要取出對應的session,將其invalidate就行了。
至此衫陵,實現思路已經明了,聒噪了這么久,大家都急不可耐地想看代碼了吧?以下是代碼:
前置準備,jsp界面
界面很簡單,只是一個簡單的登錄界面
form action ="%=request.getContextPath()%/UserWXPServlet" method = "post"
用戶名?input type = "text" name = "username"/br/
密碼?input type = "text" name = "password"/br/
input type = "submit" value ="提交"/
/form
成功后跳轉頁面
歡迎:${sessionScope.user.username}登陸!br/
我這沒有寫失敗頁面,大家可以自己寫,失敗頁面也沒什么好說的了
entity和登錄的實現
user的javabean
private String username;
private String password;
public User() {
}
public User(String user, String password) {
super();
this.username = user;
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
登錄user的service實現方法,這里就不寫dao和接口了,一切以簡單為
public boolean dologin(User user){
Properties pro = new Properties();
InputStream is = UserWXPServlet.class.getClassLoader().getResourceAsStream("user_wxp.properties");
String password = null;
System.out.println(is+"---------"+pro);
if(user==null){
return false;
}
try {
pro.load(is);
password = pro.getProperty(user.getUsername());
if(user.getPassword()!=nulluser.getPassword().equals(password)){
System.out.println("登陸成功");
return true;
}
} catch (IOException e) {
e.printStackTrace();
}finally{
if(is!=null){
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return false;
}
登錄成功返回true,失敗則返回false。
選中要注釋信改巧的代碼
eclipse注釋代碼快捷鍵滑鍵:alt+shift+/
取消殲碼注釋 :alt+shift+\
package X3DBuilder;
import java.io.*;
public class X3DCreator
{
public int xBins;
public int yBins;
public int i;
public int k;
public float min =0;
public float max = 0;
public double xSpacing;
public double zSpacing;
public double scalefactor;
public float[][] data;
public float[][] data2;
public float[] data1;
public X3DCreator() throws IOException
{
//導入文件test1513.data,并建立通向test1513.data的輸入流
BufferedReader in = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("test1513.data")));
//從文件中讀取第一行,并且將其格式化成數字xBins
xBins = Integer.parseInt(in.readLine());
//從文件中讀取第二行,并且將其格式化成數字yBins
yBins = Integer.parseInt(in.readLine());
//算法,計算兩數各自減一后的倒數
xSpacing = 1.0/(xBins-1);
zSpacing = 1.0/(yBins-1);
//將兩數分別儲存到數組data 中
data = new float[xBins][yBins];
//將兩數的乘積儲存到數組data1 中
data1 = new float[xBins*yBins];
//將兩數分別儲存到數組data2 中
data2 = new float[yBins][xBins];
for (i=0; ixBins; i++)
for (int j=0; jyBins; j++){
//繼續從文件的第三行開始一行一行讀取信息.并將讀出的數據放在data中
data[i][j] = Float.parseFloat(in.readLine());
//通過多次循環比伍猜春較獲得數組data中的最大值并賦值給max
if (max data[i][j])
max = data[i][j];
//通過多次循環將二維數組data中的數據全部放置到數組data1中
data1[k]= data[i][j];
k=k+1;
}
//賦值max的倒兆悶數給scalefactor
scalefactor = 1.0/max;
//關閉讀取文件的流對象
in.close();
//打印data1的第16 個元素
System.out.println(data1[16]);
//打印data所有元素的個數
System.out.println(k);
for (i=0; iyBins; i++)
for (int j=0; jxBins; j++){
//循環賦值
data2[i][j] = data1[j*yBins+i];
}
//創建寫入文件test.x3d的流
BufferedWriter fout = new BufferedWriter(new FileWriter("test.x3d"));
//創建讀取文件x3d1.txt的流
BufferedReader in2 = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("x3d1.txt")));
String inputLine;
while ((inputLine = in2.readLine()) != null) {
//fout.write(inputLine);
//一行一行把從文件x3d1.txt讀取的字符串寫入文件test.x3d。
fout.append(inputLine);
//寫入一個行分隔符,腔耐也就是換行。
fout.newLine();
}
fout.newLine();
//下面應該是寫入一些xml內容
fout.append("ElevationGrid height ='");
for (i=0; iyBins; i++)
for (int j=0; jxBins; j++)
{
// fout.append(" "+scalefactor*data2[i][j]+" ");
fout.append(" "+data2[i][j]+" ");
}
fout.append("'");
fout.append(" xDimension='" + xBins + " ' ");
fout.append(" xSpacing='" + xSpacing + " '");
fout.append(" zDimension='" + yBins + "' ");
fout.append(" zSpacing='" + zSpacing + "'/ ");
fout.newLine();
//關閉讀取流
in2.close();
// BufferedWriter fout2 = new BufferedWriter(new FileWriter("test.svg",true));
BufferedReader in3 = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("x3d2.txt")));
String inputLine2;
while ((inputLine2 = in3.readLine()) != null) {
//繼續將文件x3d2.txt的內容也寫入到test.x3d中
fout.append(inputLine2);
fout.newLine();
}
//關閉讀取文件流
in3.close();
//關閉寫入文件流.
fout.close();
}
}
//結束
分享名稱:java注冊代碼在線 java登錄注冊代碼
地址分享:http://vcdvsql.cn/article32/ddpsjpc.html
成都網站建設公司_創新互聯,為您提供響應式網站、服務器托管、網站收錄、、ChatGPT、網站建設
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯