如何用java编写 网页
一般在网上有免费的界面提供下载,有一定的html,css,脚本方面的知识,即使不懂,也能自我修改达到你要求的效果 算了我直接给你代码得了
创新互联是一家集网站建设,任丘企业网站建设,任丘品牌网站建设,网站定制,任丘网站建设报价,网络营销,网络优化,任丘网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
*************************************test.html*********************************************************
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=gb2312" /
title3列固定宽度居中+头部+尾部——a href=""标准之路;/a/title
link href="layout.css" rel="stylesheet" type="text/css" /
/head
body
div id="container"
div id="header"This is the Header/div
div id="mainContent"
div id="sidebar"This is the sidebar/div
div id="sidebar2"This is the sidebar2/div
div id="content"3列固定宽度居中+头部+尾部——a href=""标准之路;/a/div
/div
div id="footer"This is the footer/div
/div
/body
/html
********************************************layout.css *************************************************
body { font-family:Verdana; font-size:14px; margin:0;}
#container {margin:0 auto; width:900px;}
#header { height:100px; background:#6cf; margin-bottom:5px;}
#mainContent { height:500px; margin-bottom:5px;}
#sidebar { float:left; width:200px; height:500px; background:#9ff;}
#sidebar2 { float:right; width:200px; height:500px; background:#9ff;}
#content { margin:0 205px !important; margin:0 202px; height:500px; background:#cff;}
#footer { height:60px; background:#6cf;}
如何用java写网页
用MyEclipse新建WEB项目,跟你新建java项目是同一级别目录下的。要写网页就是JSP了,JSP开发你要学会servlet和jsp,这是最起码的,servlet就是java代码了,jsp类似于html。
求用java编登录页面,可以连接MySql 数据库
第一步:创建一个查询过程,因为在登录时要根据用户名查询用户密码
此步要用到pl/sql编程知识,代码如下:
create or replace procedure sel_user(uname in varchar2,pass out varchar2) is
begin
select users.password into pass from users where users.username=uname and rownum = 1;
end;
第二步:编写登录页面(login.java)(采用纯java+servlet编写)
//login.java如下
package cn.hnu;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class testhtml extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html;charset=gbk");
try {
PrintWriter pw = resp.getWriter();
pw.println("html");
pw.println("head");
pw.println("title");
pw.println("用户登录");
pw.println("/title");
pw.println("/head");
pw.println("body");
pw.println("h1用户登录/h1");
pw.println("hr");
pw.println("form method=post action=loginCl");
pw.println("用户名:input type=text name=userNamebr");
pw.println("密nbspnbsp码:input type=password name=passwordbr");
pw.println("input type=submit value=登录");
pw.println("input type=reset value=重置");
pw.println("/form");
pw.println("/body");
pw.println("/html");
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doGet(req, resp);
}
}
第三步:编程成功登录页面(wel.java) //wel.java如下,它主要用于用户正常登录后显示信息给用户
package cn.hnu;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class Wel extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
//防止用户非法登录
HttpSession hs = req.getSession();
String s = (String)hs.getAttribute("pass");
if(s == null){
resp.sendRedirect("login");
}
PrintWriter pw = resp.getWriter();
pw.write("welcome,hello");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doGet(req, resp);
}
}
第四步:编写login处理页面(loginCl.java)
package cn.hnu;
import java.io.IOException;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class loginCl extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
String u = req.getParameter("userName");
String p = req.getParameter("password");
//查询数据库
String pa=null;
Connection ct = null;
CallableStatement cs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
ct = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oracle",
"scott", "tiger");
cs = ct.prepareCall("{call sel_user(?,?)}");
cs.setString(1, u);
cs.registerOutParameter(2, oracle.jdbc.OracleTypes.VARCHAR);
cs.execute();
pa = cs.getString(2);
System.out.println("u=" + u + " p=" + pa);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (cs != null) {
cs.close();
}
if (ct != null) {
ct.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//验证用户信息是否合法
if (p.equals(pa)) {
HttpSession hs = req.getSession(true);//防止用户非法登录
hs.setAttribute("pass", "OK");
resp.sendRedirect("wel");
} else {
resp.sendRedirect("login");
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doGet(req, resp);
}
}
亲,sql可以换成MySQL
这个没关系的,别的都可以照搬来用
用java编写一个程序。设计一个页面,第一行含有三个按钮,第二行正中间含有一
代码:
package FrameText;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FrameDemo extends JFrame {
JButton jbtwo ,jbHello, jbBye;
public FrameDemo() {
setLayout(new GridLayout(3, 1));// 3行1列布局
JPanel jp1 = new JPanel();// 第一行
JButton jb1 = new JButton("第一个按钮");
JButton jb2 = new JButton("第二个按钮");
JButton jb3 = new JButton("第三个按钮");
jp1.add(jb1);
jp1.add(jb2);
jp1.add(jb3);
add(jp1);
JPanel jp2 = new JPanel();// 第二行
JButton jbtwo = new JButton("第四个按钮");
jp2.add(jbtwo);
add(jp2);
JPanel jp3 = new JPanel();// 第三行
jbHello = new JButton("第五个按钮");
jbBye = new JButton("第六个按钮");
jp3.add(jbHello);
jp3.add(jbBye);
add(jp3);
setSize(380, 180);
setTitle("窗口");
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
//点击按钮后响应
public static void main(String[] args) {
new FrameDemo();
}
}
运行时可调用浏览器打开一个网页,网页地址在代码中的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代码怎么写?
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
class LoginFrm extends JFrame implements ActionListener
{
JLabel lbl1=new JLabel("用户名");
JLabel lbl2=new JLabel("密码");
JTextField txt=new JTextField(15);
JPasswordField pf=new JPasswordField();
JButton btn1=new JButton("确定");
JButton btn2=new JButton("取消");
public LoginFrm()
{
this.setTitle("登陆");
JPanel jp=(JPanel)this.getContentPane();
jp.setLayout(new GridLayout(3,2,10,10));
jp.add(lbl1);jp.add(txt);
jp.add(lbl2);jp.add(pf);
jp.add(btn1);jp.add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btn1)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:MyDB","","");
Statement cmd=con.createStatement();
ResultSet rs=cmd.executeQuery("select * from loginAndpassword where login='"+txt.getText()+"' and password='"+pf.getText()+"'");
if(rs.next())
{
JOptionPane.showMessageDialog(null,"登陆成功!");
}
else
JOptionPane.showMessageDialog(null,"用户名或密码错误!");
} catch(Exception ex){}
if(ae.getSource()==btn2)
{
txt.setText("");
pf.setText("");
}
}
}
public static void main(String arg[])
{
JFrame.setDefaultLookAndFeelDecorated(true);
LoginFrm frm=new LoginFrm();
frm.setSize(400,200);
frm.setVisible(true);
}
}
网站题目:java用代码编写页面 jsp页面写java代码
链接URL:http://cqwzjz.cn/article/dooocjo.html