本文目錄一覽:
- 1、java程序中如何實現單擊頁面a中的按鈕跳轉到頁面b
- 2、用java怎樣編寫登錄頁面,成功登錄跳轉到下一個頁面,求代碼
- 3、java中如何做到界面的跳轉?
- 4、java按一下按鈕就能跳到另一個界面怎麼實現
- 5、在java web開發中,凡是能實現頁面跳轉的方法有哪些?具體列出這些方法的實現語句
- 6、jsp中,通過java後台控制跳轉的頁面;
java程序中如何實現單擊頁面a中的按鈕跳轉到頁面b
java程序中的jsp頁面點擊按鈕跳轉到頁面b的方式如下:
1.jsp頁面的方式如下:a href=”….b.jsp”跳轉/a
response.sendRedirect(“b.jsp”)
jsp:forward page=”b.jsp”/
2.在swing里,給button加一個監聽器,然後在監聽事件中打開另一個頁面。
在jsp或是靜態網頁里,onclick=「JavaScript:window.location=』xx『」
用java怎樣編寫登錄頁面,成功登錄跳轉到下一個頁面,求代碼
說說servlet裡面的方法:
public void ValidateUserPass(String user,String pass){
RequestDispathcher rd =null
//假使你的代碼是從DB中獲取
DBFactory db=DBFactoryImpl.getDBFactoryInstance();//得到資料庫鏈接
flg=db.findUser(user,pass);
// 這裡是不存在用戶
if(flg.hasNext()==-1){
// 登錄時錯誤了,一般我們會給用戶一個提示
session.setAttirbute(“msg”,”對不起,用戶名或密碼錯誤”);
RequestDispathcher rd = req.getRequesDispatcher(“login.jsp”);
rd.forward(request, reponse);//將請求對象和響應對象傳遞進來
} // 這裡是存在當前用戶
else{
//當然這裡登錄成功時,我們要把當前用戶寫到session裡面保存
session.setAttirbute(“userName”,user);
//這個請求轉發語句
request.sendRedirect(“index.html”);
}
}
// * 上述代碼,你可以參考下我的方法,我也很久沒做JAVA開發了,我現在從事前端UI開發,本來我想在寫一個用struts 2登錄的程序的,可我現在忘得差不多了,上面我所用到的屬性建議你自己好好的研究一下,往後你將學到struts2 hibernate,Spring等一系列優秀的開源框架,說白了,這些東西的底層還是這些,只不過這些框架做了一些封裝隔離。上述代碼建議你重點理解一下:請求轉發和重定向的區別。
java中如何做到界面的跳轉?
假如有兩個frame,分別為frame1,frame2,frame1加個按鈕實現跳轉.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(“跳轉”);
this.add(jb);
jb.addActionListener(this);//加入事件監聽
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按一下按鈕就能跳到另一個界面怎麼實現
java實現的簡單登錄頁面,從一個按鈕點擊後跳轉的頁面的jframe寫法:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class jb{
public static void main(String args[]){
JFrame f=new JFrame(“點我跳轉”);
Container contentPane=f.getContentPane();
contentPane.setLayout(new GridLayout(1,2));
Icon icon=new ImageIcon(“b.jpg”);
JLabel label2=new JLabel(“a”,icon,JLabel.CENTER);
label2.setHorizontalTextPosition(JLabel.CENTER);
contentPane.setLayout(new FlowLayout( FlowLayout.CENTER,10,10));
JButton bb=new JButton(“圖片”);
bb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFrame bf=new JFrame(“新窗體”);
Icon icon=new ImageIcon(“enter.jpg”);
JLabel label2=new JLabel(icon);
bf.getContentPane().add(label2);
bf.setSize(300,360);
bf.show();
}});
contentPane.add(label2);
contentPane.add(bb);
f.pack();
f.show();
}}
在java web開發中,凡是能實現頁面跳轉的方法有哪些?具體列出這些方法的實現語句
一、跳轉到新頁面,並且是在新窗口中打開頁面:
function openHtml()
{
//do someghing here…
window.open(“xxxx.html”);
}
window是一個javascript對象,可以用它的open方法,需要注意的是,如果這個頁面不是一相相對路徑,那麼要加「http://」,比如:
function openHtml()
{
window.open(“”);
}
二、在本頁面窗口中跳轉:
function totest2()
{
window.location.assign(“test2.html”);
}
如果直接使用location.assgin()也可以,但是window.location.assign()更合理一些,當前窗口的location對象的assign()方法。
另外,location對象還有一個方法replace()也可以做頁面跳轉,它跟assign()方法的區別在於:
replace() 方法不會在 History 對象中生成一個新的紀錄。當使用該方法時,新的 URL 將覆蓋 History 對象中的當前紀錄。
jsp中,通過java後台控制跳轉的頁面;
jsp中通過後台servlet是可以跳轉頁面的。
1、客戶端跳轉
// 使用response對象的sendRedirect實現客戶端跳轉
// servlet的doGet方法
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException {
PrintWriter out = res.getWriter();
out.println(“Hello world!”);
res.sendRedirect(“test.do”); // servlet實現跳轉(客戶端跳轉)
}
2、伺服器端跳轉
// 使用RequestDispatcher介面實現伺服器端跳轉,且向目標頁面傳遞參數
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException,
IOException{
PrintWriter out = resp.getWriter();
/*
* 在servlet中實現伺服器端跳轉,並向跳轉頁面傳遞參數
*/
req.setAttribute(“name”, “haiyun”); // 為request對象添加參數
RequestDispatcher dispatcher = req.getRequestDispatcher(“test-04.jsp”); // 使用req對象獲取RequestDispatcher對象
dispatcher.forward(req, resp); // 使用RequestDispatcher對象在伺服器端向目的路徑跳轉
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/303014.html