新聞中心
用java做好的登陸界面,當?shù)顷懗晒筇D(zhuǎn)到下個頁面的代碼是什么?
用java做好的登陸界面,當?shù)顷懗晒筇D(zhuǎn)到下個頁面的代碼如下:
10年積累的網(wǎng)站設(shè)計制作、成都網(wǎng)站制作經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認識你,你也不認識我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有北塔免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
如果登陸驗證是在jsp中,那么跳轉(zhuǎn)可以寫成
1.response.sendRedirct("跳轉(zhuǎn)到頁面");
2.jsp:forward page="跳轉(zhuǎn)頁面"/
3.response.setHeader("Location","");
如果是登陸驗證是在servlet中,那么中轉(zhuǎn)可以寫成
1.response.sendRedirect("/a.jsp");
2.RequestDispatcher dispatcher = request.getRequestDispatcher("/a.jsp");
dispatcher .forward(request, response);
也可以使用js代碼實現(xiàn):
script
function validate(){
window.location.href="/index.jsp";
}
/script
用java怎樣編寫登錄頁面,成功登錄跳轉(zhuǎn)到下一個頁面,求代碼
說說servlet里面的方法:
public void?ValidateUserPass(String user,String pass){
RequestDispathcher?rd =null
//假使你的代碼是從DB中獲取
DBFactory?db=DBFactoryImpl.getDBFactoryInstance();//得到數(shù)據(jù)庫鏈接
flg=db.findUser(user,pass);
//?這里是不存在用戶
if(flg.hasNext()==-1){
//?登錄時錯誤了,一般我們會給用戶一個提示
session.setAttirbute("msg","對不起,用戶名或密碼錯誤");
RequestDispathcher?rd?=?req.getRequesDispatcher("login.jsp");
rd.forward(request,?reponse);//將請求對象和響應(yīng)對象傳遞進來
}???//?這里是存在當前用戶
else{
//當然這里登錄成功時,我們要把當前用戶寫到session里面保存
session.setAttirbute("userName",user);
//這個請求轉(zhuǎn)發(fā)語句
request.sendRedirect("index.html");
}
}
// * 上述代碼,你可以參考下我的方法,我也很久沒做JAVA開發(fā)了,我現(xiàn)在從事前端UI開發(fā),本來我想在寫一個用struts 2登錄的程序的,可我現(xiàn)在忘得差不多了,上面我所用到的屬性建議你自己好好的研究一下,往后你將學到struts2 hibernate,Spring等一系列優(yōu)秀的開源框架,說白了,這些東西的底層還是這些,只不過這些框架做了一些封裝隔離。上述代碼建議你重點理解一下:請求轉(zhuǎn)發(fā)和重定向的區(qū)別。
java中如何做到界面的跳轉(zhuǎn)?
假如有兩個frame,分別為frame1,frame2,frame1加個按鈕實現(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)聽
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();//點擊按鈕時frame1銷毀,new一個frame2
new frame2();
}
}
}
frame2是個單純的界面
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)代碼 java如何實現(xiàn)跳轉(zhuǎn)到指定頁面
本文鏈接:http://fisionsoft.com.cn/article/dddcjjc.html