java頁(yè)面自動(dòng)跳轉(zhuǎn)代碼 java如何實(shí)現(xiàn)跳轉(zhuǎn)到指定頁(yè)面

用java怎樣編寫登錄頁(yè)面,成功登錄跳轉(zhuǎn)到下一個(gè)頁(yè)面,求代碼

說(shuō)說(shuō)servlet里面的方法:

成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供昭通企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站設(shè)計(jì)制作、做網(wǎng)站、H5頁(yè)面制作、小程序制作等業(yè)務(wù)。10年已為昭通眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站制作公司優(yōu)惠進(jìn)行中。

public void?ValidateUserPass(String user,String pass){

RequestDispathcher?rd =null

//假使你的代碼是從DB中獲取

DBFactory?db=DBFactoryImpl.getDBFactoryInstance();//得到數(shù)據(jù)庫(kù)鏈接

flg=db.findUser(user,pass);

//?這里是不存在用戶

if(flg.hasNext()==-1){

//?登錄時(shí)錯(cuò)誤了,一般我們會(huì)給用戶一個(gè)提示

session.setAttirbute("msg","對(duì)不起,用戶名或密碼錯(cuò)誤");

RequestDispathcher?rd?=?req.getRequesDispatcher("login.jsp");

rd.forward(request,?reponse);//將請(qǐng)求對(duì)象和響應(yīng)對(duì)象傳遞進(jìn)來(lái)

}???//?這里是存在當(dāng)前用戶

else{

//當(dāng)然這里登錄成功時(shí),我們要把當(dāng)前用戶寫到session里面保存

session.setAttirbute("userName",user);

//這個(gè)請(qǐng)求轉(zhuǎn)發(fā)語(yǔ)句

request.sendRedirect("index.html");

}

}

// * 上述代碼,你可以參考下我的方法,我也很久沒(méi)做JAVA開(kāi)發(fā)了,我現(xiàn)在從事前端UI開(kāi)發(fā),本來(lái)我想在寫一個(gè)用struts 2登錄的程序的,可我現(xiàn)在忘得差不多了,上面我所用到的屬性建議你自己好好的研究一下,往后你將學(xué)到struts2 hibernate,Spring等一系列優(yōu)秀的開(kāi)源框架,說(shuō)白了,這些東西的底層還是這些,只不過(guò)這些框架做了一些封裝隔離。上述代碼建議你重點(diǎn)理解一下:請(qǐng)求轉(zhuǎn)發(fā)和重定向的區(qū)別。

用java做好的登陸界面,當(dāng)?shù)顷懗晒筇D(zhuǎn)到下個(gè)頁(yè)面的代碼是什么?

用java做好的登陸界面,當(dāng)?shù)顷懗晒筇D(zhuǎn)到下個(gè)頁(yè)面的代碼如下:

如果登陸驗(yàn)證是在jsp中,那么跳轉(zhuǎn)可以寫成

1.response.sendRedirct("跳轉(zhuǎn)到頁(yè)面");

2.jsp:forward page="跳轉(zhuǎn)頁(yè)面"/

3.response.setHeader("Location","");

如果是登陸驗(yàn)證是在servlet中,那么中轉(zhuǎn)可以寫成

1.response.sendRedirect("/a.jsp");

2.RequestDispatcher dispatcher = request.getRequestDispatcher("/a.jsp");

dispatcher .forward(request, response);

也可以使用js代碼實(shí)現(xiàn):

script

function validate(){

window.location.href="/index.jsp";

}

/script

java中如何做到界面的跳轉(zhuǎn)?

假如有兩個(gè)frame,分別為frame1,frame2,frame1加個(gè)按鈕實(shí)現(xiàn)跳轉(zhuǎn).frame1代碼如下

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

public class frame1 extends JFrame implements ActionListener{

/**

* @param args

*/

private JButton jb;

public frame1()

{

this.setSize(300, 200);

this.setLocation(300, 400);

jb=new JButton("跳轉(zhuǎn)");

this.add(jb);

jb.addActionListener(this);//加入事件監(jiān)聽(tīng)

this.setVisible(true);

}

public static void main(String[] args) {

// TODO Auto-generated method stub

frame1 frame=new frame1();

}

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

if(e.getSource()==jb)

{

this.dispose();//點(diǎn)擊按鈕時(shí)frame1銷毀,new一個(gè)frame2

new frame2();

}

}

}

frame2是個(gè)單純的界面

import javax.swing.JButton;

import javax.swing.JFrame;

public class frame2 extends JFrame{

/**

* @param args

*/

public frame2()

{

this.setSize(300, 200);

this.setLocation(300, 400);

this.setVisible(true);

}

public static void main(String[] args) {

// TODO Auto-generated method stub

frame2 frame=new frame2();

}

}

Java單擊確定按鈕跳轉(zhuǎn)到另一個(gè)界面的代碼。調(diào)到另一個(gè)類的界面

public

void

actionPerformed(ActionEvent

e)

{

if(e.getSource()

==

button)

//或者e.getActionCommand().equals("確定')

{

Login

window

=

new

Login();

window.frame.setVisible(true);

}

}

這樣就可以了。但是要在Login類中定義一個(gè)全局變量frame,即:private

JFrame

frame,并且記得初始化,frame

=new

JFrame();

文章名稱:java頁(yè)面自動(dòng)跳轉(zhuǎn)代碼 java如何實(shí)現(xiàn)跳轉(zhuǎn)到指定頁(yè)面
文章源于:http://bm7419.com/article16/dohgigg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、外貿(mào)建站、網(wǎng)站營(yíng)銷、網(wǎng)站收錄、定制開(kāi)發(fā)、品牌網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都app開(kāi)發(fā)公司