网页登陆java代码 登录页面java代码

运行时可调用浏览器打开一个网页,网页地址在代码中的java代码怎么写?网页地址在代码中的java代码写法如下:
packagecom.test;
importjava.lang.reflect.Method;
//实现打开浏览器并跳到指定网址的类
publicclassBareBonesBrowserLaunch{
publicstaticvoidopenURL(Stringurl){
try{
browse(url);
}catch(Exceptione){
}
}
privatestaticvoidbrowse(Stringurl)throwsException{
//获取操作系统的名字
StringosName=System.getProperty("os.name","");
if(osName.startsWith("MacOS")){
//苹果的打开方式
ClassfileMgr=Class.forName("com.apple.eio.FileManager");
MethodopenURL=fileMgr.getDeclaredMethod("openURL",newClass[]{String.class});
openURL.invoke(null,newObject[]{url});
}elseif(osName.startsWith("Windows")){
//windows的打开方式 。
Runtime.getRuntime().exec("rundll32url.dll,FileProtocolHandler" url);
}else{
//UnixorLinux的打开方式
String[]browsers={"firefox","opera","konqueror","epiphany","mozilla","netscape"};
Stringbrowser=null;
for(intcount=0;countbrowsers.lengthbrowser==null;count)
//执行代码,在brower有值后跳出 ,
//这里是如果进程创建成功了,==0是表示正常结束 。
if(Runtime.getRuntime().exec(newString[]{"which",browsers[count]}).waitFor()==0)
browser=browsers[count];
if(browser==null)
thrownewException("Couldnotfindwebbrowser");
else
//这个值在上面已经成功的得到了一个进程 。
Runtime.getRuntime().exec(newString[]{browser,url});
}
}
}
//主方法测试类
publicstaticvoidmain(String[]args){
Stringurl="";
BareBonesBrowserLaunch.openURL(url);
}
java web网页登录功能原理(最好有代码?想要实现一个简单网页登陆java代码的登录功能的话网页登陆java代码,可以使用Servlet jsp来实现,jsp编写登录界面和登录后的要出现信息界面和登录失败的信息界面,Servlet类用来对表单提交的用户名和密码进行判断和处理 。
具体代码如下网页登陆java代码:
Servlet类网页登陆java代码:
public class DemoServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String loginname = request.getParameter("loginname");
String password = request.getParameter("password");
if(loginname.equals("a")password.equals("a")){
request.setAttribute("msg", "登录成功");
request.getRequestDispatcher("/loginsuccess.jsp").forward(request, response);
}else{
request.setAttribute("msg", "登录失败");
request.getRequestDispatcher("/loginsuccess.jsp").forward(request, response);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
jsp页面:
%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
html
head
titleDemo/title
meta http-equiv="pragma" content="no-cache"
meta http-equiv="cache-control" content="no-cache"
meta http-equiv="expires" content="0"
meta http-equiv="keywords" content="keyword1,keyword2,keyword3"
meta http-equiv="description" content="This is my page"
/head
body
form action="demoServlet" method="post"
input type="text" name="loginname"/br/
input type="password" name="password"/br/
input type="submit" value="https://www.04ip.com/post/登录"/
/form
/body
/html
登录信息页面:
%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%
%@ taglib prefix="c" uri="标签库地址"%
【网页登陆java代码 登录页面java代码】!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
html
head
titleMy JSP 'loginsuccess.jsp' starting page/title
meta http-equiv="pragma" content="no-cache"
meta http-equiv="cache-control" content="no-cache"
meta http-equiv="expires" content="0"
meta http-equiv="keywords" content="keyword1,keyword2,keyword3"
meta http-equiv="description" content="This is my page"
/head
body
${msg }
/body
/html
需要介绍一下:登录信息的这个页面中的${msg }是使用jstl标签 , 需要在jsp页面中导入jstl标签库,使用这个标签库可以节省很多代码量 。
用java做好的登陆界面 , 当登陆成功后跳转到下个页面的代码是什么?用java做好的登陆界面,当登陆成功后跳转到下个页面的代码如下:
如果登陆验证是在jsp中 , 那么跳转可以写成
1.response.sendRedirct("跳转到页面");
2.jsp:forward page="跳转页面"/
3.response.setHeader("Location","");
如果是登陆验证是在servlet中,那么中转可以写成
1.response.sendRedirect("/a.jsp");
2.RequestDispatcher dispatcher = request.getRequestDispatcher("/a.jsp");
dispatcher .forward(request, response);
也可以使用js代码实现:
script
function validate(){
window.location.href="https://www.04ip.com/index.jsp";
}
/script
登陆界面的java代码怎么写?import java.awt.*; \x0d\x0aimport javax.swing.*; \x0d\x0aimport java.awt.event.*; \x0d\x0aimport java.sql.*; \x0d\x0a\x0d\x0aclass LoginFrm extends JFrame implements ActionListener \x0d\x0a{ \x0d\x0aJLabel lbl1=new JLabel("用户名"); \x0d\x0aJLabel lbl2=new JLabel("密码"); \x0d\x0aJTextField txt=new JTextField(15); \x0d\x0aJPasswordField pf=new JPasswordField(); \x0d\x0aJButton btn1=new JButton("确定"); \x0d\x0aJButton btn2=new JButton("取消"); \x0d\x0a\x0d\x0apublic LoginFrm() \x0d\x0a{ \x0d\x0athis.setTitle("登陆"); \x0d\x0aJPanel jp=(JPanel)this.getContentPane(); \x0d\x0ajp.setLayout(new GridLayout(3,2,10,10)); \x0d\x0ajp.add(lbl1);jp.add(txt); \x0d\x0ajp.add(lbl2);jp.add(pf); \x0d\x0ajp.add(btn1);jp.add(btn2); \x0d\x0abtn1.addActionListener(this); \x0d\x0abtn2.addActionListener(this); \x0d\x0a} \x0d\x0a\x0d\x0apublic void actionPerformed(ActionEvent ae) \x0d\x0a{ \x0d\x0aif(ae.getSource()==btn1) \x0d\x0a{ \x0d\x0atry \x0d\x0a{ \x0d\x0aClass.forName("sun.jdbc.odbc.JdbcOdbcDriver")网页登陆java代码; \x0d\x0aConnection con=DriverManager.getConnection("jdbc:odbc:MyDB","",""); \x0d\x0aStatement cmd=con.createStatement(); \x0d\x0aResultSet rs=cmd.executeQuery("select * from loginAndpassword where login='" txt.getText() "' and password='" pf.getText() "'"); \x0d\x0aif(rs.next()) \x0d\x0a{ \x0d\x0aJOptionPane.showMessageDialog(null,"登陆成功网页登陆java代码!"); \x0d\x0a} \x0d\x0aelse \x0d\x0aJOptionPane.showMessageDialog(null,"用户名或密码错误网页登陆java代码!"); \x0d\x0a} catch(Exception ex){} \x0d\x0a\x0d\x0aif(ae.getSource()==btn2) \x0d\x0a{ \x0d\x0atxt.setText(""); \x0d\x0apf.setText(""); \x0d\x0a} \x0d\x0a} \x0d\x0a} \x0d\x0a\x0d\x0apublic static void main(String arg[]) \x0d\x0a{ \x0d\x0aJFrame.setDefaultLookAndFeelDecorated(true); \x0d\x0aLoginFrm frm=new LoginFrm(); \x0d\x0afrm.setSize(400,200); \x0d\x0afrm.setVisible(true); \x0d\x0a} \x0d\x0a}
关于网页登陆java代码和登录页面java代码的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读