ava要運行html代碼,需要運行在服務(wù)器端,也就是servlet容器中,經(jīng)過容器編譯解析,返回html靜態(tài)內(nèi)容,示例如下:

站在用戶的角度思考問題,與客戶深入溝通,找到白銀網(wǎng)站設(shè)計與白銀網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網(wǎng)站建設(shè)、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名申請、網(wǎng)站空間、企業(yè)郵箱。業(yè)務(wù)覆蓋白銀地區(qū)。
在servlet里面寫就可以了
引入一系列包
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
public class Servlet1 extends HttpServlet {
public void doGet(ServletRequest req,ServletResponse res)throws ServletException, IOException{try{PrintWriter pw=res.getWriter();//在瀏覽器輸出需要
pw.println("scriptscript");}catch(exception e){="" e.printstacktrace();="" 為發(fā)現(xiàn)調(diào)試錯誤}}}=""
package?example;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?javax.swing.JFrame;
import?javax.swing.JMenu;
import?javax.swing.JMenuBar;
import?javax.swing.JMenuItem;
import?javax.swing.JOptionPane;
import?javax.swing.JPanel;
import?javax.swing.border.EmptyBorder;
public?class?demo?extends?JFrame{
private?JMenuBar?menu?=?new?JMenuBar();
private?JPanel?contentPane?=?new?JPanel();
public?demo()
{
setTitle("compiler");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setJMenuBar(menu);
//JMenu?correct?=?new?JMenu("正確用例");
//JMenu?wrong?=?new?JMenu("錯誤用例");
////JMenuItem?WP?=?wrong.add("語法錯誤");
//JMenuItem?WL?=?wrong.add("詞法錯誤");
JMenu?edit?=?new?JMenu("編輯");
JMenu?help??=?new?JMenu("幫助");
JMenu?document?=?new?JMenu("文件");
JMenuItem?copy?=?edit.add("復(fù)制");
JMenu?color?=?new?JMenu("顏色");
JMenuItem?p?=?color.add("前景色");
p.addActionListener(new?ActionListener()
{
@Override
public?void?actionPerformed(ActionEvent?e)?{
JOptionPane.showMessageDialog(null,
"該項目正在建設(shè)中",?"信息",
JOptionPane.INFORMATION_MESSAGE);
}
});
JMenuItem?b?=?color.add("背景色");
b.addActionListener(new?ActionListener()
{
@Override
public?void?actionPerformed(ActionEvent?e)?{
JOptionPane.showMessageDialog(null,
"該項目正在建設(shè)中",?"信息",
JOptionPane.INFORMATION_MESSAGE);
}
});
edit.add(color);
JMenuItem?select?=?edit.add("全選");
menu.add(document);
menu.add(edit);
menu.add(help);
setLocation(400,200);
setSize(300,?300);
contentPane.setBorder(new?EmptyBorder(5,?5,?5,?5));
setContentPane(contentPane);
}
public?static?void?main(String[]args)
{
demo?browser?=?new?demo();
browser.setVisible(true);
}
}
String command = new Scanner(System.in).nextLine();
Process process = new Runtime.getRuntime().exec(command); // command為unix命令,如"ls"等
BufferedReader results = new BufferedReader(new InputStreamReader(process.getInputStream()));
String s;
while((s = results.readLine()) != null) {
System.out.println(s);
}
1.準備數(shù)據(jù)
--建表
create table PY
(
ID INT not null primary key,--主鍵
WORD VARCHAR(10),--中文字、詞
PY_CODE VARCHAR(10)--拼音
)
--導(dǎo)入數(shù)據(jù)
insert into PY(ID, WORD, PY_CODE)
values (1, '啊', 'a');
...
2.用Ajax 輸入框onChange事件 javascript
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;public class Test
{
public static void main(String[] args) throws Exception
{
PrintWriter pw = new PrintWriter("d:\\test.xml");//d:\\test.xml是你的xml文件路徑
pw.println(getHtmlConentByUrl(" "));// 是你要訪問的頁面
pw.flush();
pw.close();
}
public static String getHtmlConentByUrl(
String ssourl) {
try {
URL url = new URL(ssourl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setInstanceFollowRedirects(false);
con.setUseCaches(false);
con.setAllowUserInteraction(false);
con.connect(); StringBuffer sb = new StringBuffer();
String line = "";
BufferedReader URLinput = new BufferedReader(new InputStreamReader(con.getInputStream()));
while ((line = URLinput.readLine()) != null) {
sb.append(line);
}
con.disconnect();
return sb.toString().toLowerCase();
} catch (Exception e) {
return null;
}
}}
在獲取到的頁面內(nèi)容是字符串,這里解析有兩個辦法,一是通過dom4j把字符串轉(zhuǎn)化為dom進行解析,這樣最好,但是對方的頁面未必規(guī)范,符合dom結(jié)構(gòu)。二是通過解析字符串過濾你想要的內(nèi)容,該方法比較繁瑣,需要一些技巧。我有的就是二;
package?com.lxi;
import?java.io.BufferedReader;
import?java.io.InputStreamReader;
public?class?Rpg?{
@SuppressWarnings("unchecked")
public?static?void?main(String[]?args)?throws?Exception?{
System.out.println("在這里輸入兩個人物進行PK,以英文逗號分隔:?[BM,DH,MK]");
BufferedReader?br?=?new?BufferedReader(new?InputStreamReader(System.in));
ClassPerson?c1;
ClassPerson?c2;
try?{
String?temp?=?br.readLine();
String[]?str?=?temp.split(",");
if?(str.length?!=?2)?{
throw?new?Exception("輸入格式有誤,按默認PK");
}
c1?=?(ClassPerson)?Class.forName("com.lxi."
+?str[0].toUpperCase());
c2?=?(ClassPerson)?Class.forName("com.lxi."
+?str[1].toUpperCase());
}?catch?(Exception?e)?{
//?TODO?Auto-generated?catch?block
c1?=?(ClassPerson)?Class.forName("com.lxi.BM");
c2?=?(ClassPerson)?Class.forName("com.lxi.DH");
}
try?{
Person?p1?=?c1.newInstance();
Person?p2?=?c2.newInstance();
long?time?=?System.currentTimeMillis();
long?nextTime1?=?(long)?(time?+?p1.coldTime*1000);?//
long?nextTime2?=?(long)?(time?+?p2.coldTime*1000);?//發(fā)動攻擊的時間
System.out.println("---游戲開始---");
while?(true)?{
long?currenTime?=?System.currentTimeMillis();
if?(nextTime1??currenTime)?{??//時間到則發(fā)動攻擊
p1.hit(p2);
nextTime1?+=?p1.coldTime*1000?+?p1.waitTime*1000;?//下次攻擊時間=冷卻時間+被暈眩時間
p1.waitTime?=?0;??//回合結(jié)束,重置被暈眩時間為0
}
if?(nextTime2??currenTime)?{
p2.hit(p1);
nextTime2?+=?p2.coldTime*1000?+?p2.waitTime*1000;
p2.waitTime?=?0;
}
}
}?catch?(ClassCastException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}?catch?(InstantiationException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}?catch?(IllegalAccessException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}?catch?(Exception?e)?{
e.printStackTrace();
}
}
}
package?com.lxi;
import?java.util.Random;
class?BM?extends?Person?{
public?BM()?{
val?=?650;
coldTime?=?1.5;
fight?=?40;
chanceHit?=?3;
chanceDefense?=?3;
waitTime?=?0;
}
int?count?=?0;???//防御技能發(fā)動的次數(shù)
int?temp?=?40;???//攻擊力,值同fight
boolean?hitFlag?=?false;
boolean?defenseFlag?=?false;
Random?rand?=?new?Random();
public?void?hit(Person?p)?{
if?(rand.nextInt(10)??chanceHit)?{
fight?=?fight?*?2;???//發(fā)動雙倍攻擊
hitFlag?=?true;
}
int?hurt?=?p.defense(this);
p.val?=?p.val?-?hurt;
fight?=?temp;?????//還原為單倍攻擊
if?(p.val?=?0)?{
System.out.println(this.getClass().getSimpleName()?+?"勝出!");
System.exit(0);
}
System.out.println(this.getClass().getSimpleName()?+?"攻擊"
+?p.getClass().getSimpleName()?+?","
+?this.getClass().getSimpleName()
+?(this.hitFlag???"發(fā)動攻擊技能???"?:?"未發(fā)動攻擊技能???")
+?p.getClass().getSimpleName()
+?(this.defenseFlag???"發(fā)動防御技能???"?:?"未發(fā)動防御技能???")
+?this.getClass().getSimpleName()?+?":"?+?this.val?+?","
+?p.getClass().getSimpleName()?+?":"?+?p.val);
hitFlag?=?false;
defenseFlag?=?false;
}
public?int?defense(Person?p)?{
if?(rand.nextInt(10)??chanceDefense)?{
if?(count?!=?0)?{
p.val?=?p.val?-?p.fight;
count++;
defenseFlag?=?true;
if?(p.val?=?0)?{
System.out.println(this.getClass().getSimpleName()?+?"勝出!");
System.exit(0);
}
}
}
return?p.fight;
}
}
class?MK?extends?Person?{
public?MK()?{
val?=?700;
coldTime?=?2.5;
fight?=?50;
chanceDefense?=?6;
chanceHit?=?3;
waitTime?=?0;
}
boolean?hitFlag?=?false;
boolean?defenseFlag?=?false;
Random?rand?=?new?Random();
public?void?hit(Person?p)?{
if?(rand.nextInt(10)??chanceHit)?{
p.waitTime?=?3;???//使對方暈眩3s
hitFlag?=?true;
}
int?hurt?=?p.defense(this);
p.val?=?p.val?-?hurt;
if?(p.val?=?0)?{
System.out.println(this.getClass().getSimpleName()?+?"勝出!");
System.exit(0);
}
System.out.println(this.getClass().getSimpleName()?+?"攻擊"
+?p.getClass().getSimpleName()?+?","
+?this.getClass().getSimpleName()
+?(this.hitFlag???"發(fā)動攻擊技能???"?:?"未發(fā)動攻擊技能???")
+?p.getClass().getSimpleName()
+?(this.defenseFlag???"發(fā)動防御技能???"?:?"未發(fā)動防御技能???")
+?this.getClass().getSimpleName()?+?":"?+?this.val?+?","
+?p.getClass().getSimpleName()?+?":"?+?p.val);
hitFlag?=?false;
defenseFlag?=?false;
}
public?int?defense(Person?p)?{
if?(rand.nextInt(10)??chanceDefense)?{
defenseFlag?=?true;
return?p.fight?/?2;???//防御技能發(fā)動,傷害減半
}
return?p.fight;
}
}
package?com.lxi;
import?java.io.BufferedReader;
import?java.io.InputStreamReader;
import?java.util.Random;
//三個人物的基類
abstract?class?Person?{
int?val;?????????????//生命值
double?coldTime;?????//冷卻時間
int?waitTime;????????//暈眩時間
int?fight;??????????//攻擊力
int?chanceHit;??????//發(fā)起主動技能的概率
int?chanceDefense;??//發(fā)起防御技能的概率
abstract?void?hit(Person?p);???//攻擊技能
abstract?int?defense(Person?p);?//防御技能,返回被傷害點數(shù)
}
class?DH?extends?Person?{
public?DH()?{
val?=?600;
coldTime?=?1.0;
fight?=?30;
chanceHit?=?3;??????//表示30%的概率
chanceDefense?=?3;
waitTime?=?0;
}
Random?rand?=?new?Random();
boolean?hitFlag?=?false;??????//主動技能發(fā)動的標識
boolean?defenseFlag?=?false;??//防御技能發(fā)動的標識
public?void?hit(Person?p)?{
if?(rand.nextInt(10)??chanceHit)?{??//發(fā)動主動技能
int?hurt?=?p.defense(this);
p.val?=?p.val?-?hurt;
if?(p.val?=?0)?{
System.out.println(this.getClass().getSimpleName()?+?"勝出!");
System.exit(0);
}
val?=?val?+?hurt;
if?(val??600)
val?=?600;
hitFlag?=?true;?????//標記主動技能已經(jīng)發(fā)動
}?else?{??//進行普通攻擊
int?hurt?=?p.defense(this);
p.val?=?p.val?-?hurt;
if?(p.val?=?0)?{
System.out.println(this.getClass().getSimpleName()?+?"勝出!");
System.exit(0);
}
}
System.out.println(this.getClass().getSimpleName()?+?"攻擊"
+?p.getClass().getSimpleName()?+?","
+?this.getClass().getSimpleName()
+?(this.hitFlag???"發(fā)動攻擊技能???"?:?"未發(fā)動攻擊技能???")
+?p.getClass().getSimpleName()
+?(this.defenseFlag???"發(fā)動防御技能???"?:?"未發(fā)動防御技能???")
+?this.getClass().getSimpleName()?+?":"?+?this.val?+?","
+?p.getClass().getSimpleName()?+?":"?+?p.val);
hitFlag?=?false;?????//
defenseFlag?=?false;?//重置標記,下次重用
}
public?int?defense(Person?p)?{
if?(rand.nextInt(10)??chanceDefense)?{
defenseFlag?=?true;???//標記防御技能已經(jīng)發(fā)動
return?0;
}?else?{
return?p.fight;
}
}
}
當前題目:dhjava代碼實現(xiàn) Dhvaja
分享URL:http://chinadenli.net/article0/dodpcoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、響應(yīng)式網(wǎng)站、定制網(wǎng)站、微信公眾號、Google、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)