導航:首頁 > 編程語言 > java格式化html

java格式化html

發布時間:2022-08-12 07:28:34

java中怎麼輸出html文件

可以用:File f_html = new File("Login.html");
f_html.createNewFile();
要想生成html頁面的話,容器會替我們直接把jsp編譯成servlet輸出成html靜態頁面進行展示。
你要像手動輸出html的展示內容可以自己寫一個servlet,使用output方法輸出html標簽代碼段直接列印到客戶端。
還有如果你想寫入html文件的話,你可以通過fileinput位元組寫入。(這種寫法servlet教程上很多實例,包括如何生成文件,如何通過位元組或者字元流的形式寫入和保存)

❷ 如何在java中實現自動生成html

創建一個StringBuilder對象,通過append方法來為其添加html語句。
StringBuilder sb = new StringBuilder();
Properties fileProperties = getProperties("file");
Properties sqlProperties = getProperties("sql");
PrintStream printStream = new PrintStream(new FileOutputStream(
"report.html"));
sb.append("<html>");
sb.append("<head>");
sb.append("<title>每日運營報表</title>");
sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
sb.append("<style type=\"text/css\">");
sb.append("TABLE{border-collapse:collapse;border-left:solid 1 #000000; border-top:solid 1 #000000;padding:5px;}");
sb.append("TH{border-right:solid 1 #000000;border-bottom:solid 1 #000000;}");
sb.append("TD{font:normal;border-right:solid 1 #000000;border-bottom:solid 1 #000000;}");
sb.append("</style></head>");
sb.append("<body bgcolor=\"#FFF8DC\">");
sb.append("<div align=\"center\">");
sb.append("<br/>");
sb.append("<br/>");
List<Map<String, Object>> result1 = getRpt(sqlProperties
.getProperty("sql1"));
for (Map.Entry<String, Object> m : result1.get(0).entrySet()) {
sb.append(fileProperties.getProperty("file1"));
sb.append(m.getValue());
}
sb.append("<br/><br/>");

輸出
sb.append("</div></body></html>");
printStream.println(sb.toString());

❸ java轉換html代碼

"<a href=\"xxx.html\" title=\"test\"">
這樣就OK了。。。。如果我理解對了樓主表達的意思
。。。

❹ java中的jacob將word文檔轉化為HTML文件問題

配置:

(1)將解壓包中的jacob.dll(x86常用,x64)拷到jdk安裝目錄下的jrein文件夾或windows安裝路徑下的WINDOWSsystem32文件夾下

(2)將jacob.jar文件拷到classpath下即可

常見問題解決:

對於」java.lang.UnsatisfiedLinkError:C:WINDOWSsystem32jacob-1.14.3-x86.dll:由於應用程序配置不正確,應用程序未能啟動。重新安裝應用程序可能會糾正」這個問題,可以通過

重新下載Jacob的jar及dll文件(最好版本比現在的低,如1.11)解決

實例製作(主要功能:標題製作,表格製作,合並表格,替換文本,頁眉頁腳,書簽處理):

importcom.jacob.activeX.ActiveXComponent;
importcom.jacob.com.Dispatch;
importcom.jacob.com.Variant;

publicclassWordOperate{
publicstaticvoidmain(Stringargs[]){
ActiveXComponentwordApp=newActiveXComponent("Word.Application");//啟動word
//.
Dispatch.put(wordApp,"Visible",newVariant(true));////設置word可見
Dispatchdocs=wordApp.getProperty("Documents").toDispatch();
//StringinFile="d:\test.doc";
//Dispatchdoc=Dispatch.invoke(docs,"Open",Dispatch.Method,
//newObject[]{inFile,newVariant(false),newVariant(false)},//參數3,false:可寫,true:只讀
//newint[1]).toDispatch();//打開文檔
Dispatchdocument=Dispatch.call(docs,"Add").toDispatch();//createnewdocument

StringuserName=wordApp.getPropertyAsString("Username");//顯示用戶信息
System.out.println("用戶名:"+userName);
//文檔對齊,字體設置////////////////////////
Dispatchselection=Dispatch.get(wordApp,"Selection").toDispatch();
Dispatchalign=Dispatch.get(selection,"ParagraphFormat")
.toDispatch();//行列格式化需要的對象
Dispatchfont=Dispatch.get(selection,"Font").toDispatch();//字型格式化需要的對象
//標題處理////////////////////////
Dispatch.put(align,"Alignment","1");//1:置中2:靠右3:靠左
Dispatch.put(font,"Bold","1");//字型租體
Dispatch.put(font,"Color","1,0,0,0");//字型顏色紅色
Dispatch.call(selection,"TypeText","Word文檔處理");//寫入標題內容
Dispatch.call(selection,"TypeParagraph");//空一行段落
Dispatch.put(align,"Alignment","3");//1:置中2:靠右3:靠左
Dispatch.put(selection,"Text","");
Dispatch.call(selection,"MoveDown");//游標標往下一行
//表格處理////////////////////////
Dispatchtables=Dispatch.get(document,"Tables").toDispatch();
Dispatchrange=Dispatch.get(selection,"Range").toDispatch();
Dispatchtable1=Dispatch.call(tables,"Add",range,newVariant(3),
newVariant(2),newVariant(1)).toDispatch();//設置行數,列數,表格外框寬度
//所有表格
VarianttableAmount=Dispatch.get(tables,"count");
System.out.println(tableAmount);
//要填充的表格
Dispatcht1=Dispatch.call(tables,"Item",newVariant(1))
.toDispatch();
Dispatcht1_row=Dispatch.get(t1,"rows").toDispatch();//所有行
intt1_rowNum=Dispatch.get(t1_row,"count").getInt();
Dispatch.call(Dispatch.get(t1,"columns").toDispatch(),"AutoFit");//自動調整
intt1_colNum=Dispatch.get(Dispatch.get(t1,"columns").toDispatch(),
"count").getInt();
System.out.println(t1_rowNum+""+t1_colNum);
for(inti=1;i<=t1_rowNum;i++){
for(intj=1;j<=t1_colNum;j++){
Dispatchcell=Dispatch.call(t1,"Cell",newVariant(i),
newVariant(j)).toDispatch();//行,列
Dispatch.call(cell,"Select");
Dispatch.put(selection,"Text","cell"+i+j);//寫入word的內容
Dispatch.put(font,"Bold","0");//字型租體(1:租體0:取消租體)
Dispatch.put(font,"Color","1,1,1,0");//字型顏色
Dispatch.put(font,"Italic","1");//斜體1:斜體0:取消斜體
Dispatch.put(font,"Underline","1");//下劃線
DispatchRange=Dispatch.get(cell,"Range").toDispatch();
StringcellContent=Dispatch.get(Range,"Text").toString();
System.out.println((cellContent.substring(0,cellContent
.length()-1)).trim());
}
Dispatch.call(selection,"MoveDown");//游標往下一行(才不會輸入蓋過上一輸入位置)
}
//合並單元格////////////////////////
Dispatch.put(selection,"Text","");
Dispatch.call(selection,"MoveDown");//游標標往下一行
Dispatchrange2=Dispatch.get(selection,"Range").toDispatch();
Dispatchtable2=Dispatch.call(tables,"Add",range2,newVariant(8),
newVariant(4),newVariant(1)).toDispatch();//設置行數,列數,表格外框寬度
Dispatcht2=Dispatch.call(tables,"Item",newVariant(2))
.toDispatch();
DispatchbeginCell=Dispatch.call(t2,"Cell",newVariant(1),
newVariant(1)).toDispatch();
DispatchendCell=Dispatch.call(t2,"Cell",newVariant(4),
newVariant(4)).toDispatch();
Dispatch.call(beginCell,"Merge",endCell);

for(introw=1;row<=Dispatch.get(
Dispatch.get(t2,"rows").toDispatch(),"count").getInt();row++){
for(intcol=1;col<=Dispatch.get(
Dispatch.get(t2,"columns").toDispatch(),"count").getInt();col++){

if(row==1){
Dispatchcell=Dispatch.call(t2,"Cell",newVariant(1),
newVariant(1)).toDispatch();//行,列
Dispatch.call(cell,"Select");
Dispatch.put(font,"Color","1,1,1,0");//字型顏色
Dispatch.put(selection,"Text","mergeCell!");
}else{
Dispatchcell=Dispatch.call(t2,"Cell",newVariant(row),
newVariant(col)).toDispatch();//行,列
Dispatch.call(cell,"Select");
Dispatch.put(font,"Color","1,1,1,0");//字型顏色
Dispatch.put(selection,"Text","cell"+row+col);
}
}
Dispatch.call(selection,"MoveDown");
}
//Dispatch.call(selection,"MoveRight",newVariant(1),newVariant(1));//取消選擇
//Objectcontent=Dispatch.get(doc,"Content").toDispatch();
//Word文檔內容查找及替換////////////////////////
Dispatch.call(selection,"TypeParagraph");//空一行段落
Dispatch.put(align,"Alignment","3");//1:置中2:靠右3:靠左
Dispatch.put(font,"Color",0);
Dispatch.put(selection,"Text","歡迎,Hello,world!");
Dispatch.call(selection,"HomeKey",newVariant(6));//移到開頭
Dispatchfind=Dispatch.call(selection,"Find").toDispatch();//獲得Find組件
Dispatch.put(find,"Text","hello");//查找字元串"hello"
Dispatch.put(find,"Forward","True");//向前查找
//Dispatch.put(find,"Format","True");//設置格式
Dispatch.put(find,"MatchCase","false");//大小寫匹配
Dispatch.put(find,"MatchWholeWord","True");//全字匹配
Dispatch.call(find,"Execute");//執行查詢
Dispatch.put(selection,"Text","你好");//替換為"你好"
//使用方法傳入的參數parameter調用word文檔中的MyWordMacro宏//
//Dispatch.call(document,macroName,parameter);
//Dispatch.invoke(document,macroName,Dispatch.Method,parameter,newint[1]);
//頁眉,頁腳處理////////////////////////
DispatchActiveWindow=wordApp.getProperty("ActiveWindow")
.toDispatch();
DispatchActivePane=Dispatch.get(ActiveWindow,"ActivePane")
.toDispatch();
DispatchView=Dispatch.get(ActivePane,"View").toDispatch();
Dispatch.put(View,"SeekView","9");//9是設置頁眉
Dispatch.put(align,"Alignment","1");//置中
Dispatch.put(selection,"Text","這里是頁眉");//初始化時間
Dispatch.put(View,"SeekView","10");//10是設置頁腳
Dispatch.put(align,"Alignment","2");//靠右
Dispatch.put(selection,"Text","這里是頁腳");//初始化從1開始
//書簽處理(打開文檔時處理)////////////////////////
//DispatchactiveDocument=wordApp.getProperty("ActiveDocument").toDispatch();
DispatchbookMarks=Dispatch.call(document,"Bookmarks").toDispatch();
booleanisExist=Dispatch.call(bookMarks,"Exists","bookMark1")
.getBoolean();
if(isExist==true){
DispatchrangeItem1=Dispatch.call(bookMarks,"Item","bookMark1")
.toDispatch();
Dispatchrange1=Dispatch.call(rangeItem1,"Range").toDispatch();
Dispatch.put(range1,"Text",newVariant("當前是書簽1的文本信息!"));
StringbookMark1Value=Dispatch.get(range1,"Text").toString();
System.out.println(bookMark1Value);
}else{
System.out.println("當前書簽不存在,重新建立!");
Dispatch.call(bookMarks,"Add","bookMark1",selection);
DispatchrangeItem1=Dispatch.call(bookMarks,"Item","bookMark1")
.toDispatch();
Dispatchrange1=Dispatch.call(rangeItem1,"Range").toDispatch();
Dispatch.put(range1,"Text",newVariant("當前是書簽1的文本信息!"));
StringbookMark1Value=Dispatch.get(range1,"Text").toString();
System.out.println(bookMark1Value);

}
//保存操作////////////////////////
Dispatch.call(document,"SaveAs","D:/wordOperate.doc");
//Dispatch.invoke((Dispatch)doc,"SaveAs",Dispatch.Method,newObject[]{htmlPath,newVariant(8)},newint[1]);//生成html文件
//0=wdDoNotSaveChanges
//-1=wdSaveChanges
//-2=wdPromptToSaveChanges
//Dispatch.call(document,"Close",newVariant(0));
////worddoc.olefunction("protect",2,true,"");
////DispatchbookMarks=wordApp.call(docs,"Bookmarks").toDispatch();
////System.out.println("bookmarks"+bookMarks.getProgramId());
////Dispatch.call(doc,"Save");//保存
////Dispatch.call(doc,"Close",newVariant(true));
////wordApp.invoke("Quit",newVariant[]{});
//wordApp.safeRelease();//Finalizerscallthismethod
}
}

❺ 怎麼利用java格式化html

提供幾種選擇:
1)放入編輯器進行Format,如editplus、eclipse
2)自己編寫「元素格式化規則」代碼
拿你的例子來說,需要在<html後面加入\n\t,可以用正則表達式進行匹配加替換

❻ 怎麼格式化自己的java/javascript/css/html代碼

① 瀏覽器發送一個連接請求給安全伺服器。
② 伺服器將自己的證書,以及同證書相關的信息發送給客戶瀏覽器。
③ 客戶瀏覽器檢查伺服器送過來的證書是否是由自己信賴的 CA 中心所簽發的。如果是,就繼續執行協議;如果不是,客戶瀏覽器就給客戶一個警告消息:警告客戶這個證書不是可以信賴的,詢問客戶是否需要繼續。
④ 接著客戶瀏覽器比較證書里的消息,例如域名和公鑰,與伺服器剛剛發送的相關消息是否一致,如果是一致的,客戶瀏覽器認可這個伺服器的合法身份。

❼ html代碼調整格式 使用java 不是求代碼

沒有必要要用java去實現對html的格式吧,方式有很多種啊,像一樓說的就可以啊,還有很多javascript類似的工具,你所要的需求估計沒有。如果有需要可以自己設計演算法實現,也可以藉助第三方的jar包幫助你實現(例如htmlparser,專門對html類型文檔進行讀寫的工具包),暫時沒有發現現成的,網上類似格式html的演算法有很多,你可以參考參考,自己做一個java版的html格式化工具。

❽ Java將字元串轉化為html然後解析

一、如果你是用的servlet,直接用
PrintWriter out = response.getWriter();
String strss="<input type='checkbox' name='proTest' id='proc74155' value='優逸系列之鼎富122002號(第11期)人民幣' onclick=floatTip.check(this,'proc74155')></label></td><td class='dr' align='left'><b><a href='74155.shtml' alt='優逸系列之鼎富122002號(第11期)人民幣' title='優逸系列之鼎富122002號(第11期)人民幣' target='_blank'>優逸系列之鼎富1..</a></b><font class='cred'>[預售]</font></td><td class='hl' align=\"left\">包商銀行</td><td class='on'>2013-12-09</td><td >2014-02-10</td><td class='hl'>人民幣</td><td class='hl'>2.00</td><td class='hl'>混合型</td><td class='hl'>--</td><td class='hl'>--</td></tr><tr align='center'><td align='center'>";
out.println(strss);
就ok了
二、如果你是在jsp中,直接 out.println(strss);

❾ 求各位大神的,java如何把一段字元串保持為html文件的java代碼

使用Java中的File類,url為文件的絕對地址,str為輸入的字元串內容。
代碼如下圖所示:

String str="i love china!"

File txt=new File("url");
if(!txt.exists()){
txt.createNewFile();
}
byte bytes[]=new byte[512];
bytes=str.getBytes(); //新加的
int b=str.length(); //改
FileOutputStream fos=new FileOutputStream(txt);
fos.write(bytes,0,b);
fos.close();

❿ 求教,如何把java源代碼用html的格式顯示出來

代碼如下:
File f_html = new File("Login.html");
f_html.createNewFile();

閱讀全文

與java格式化html相關的資料

熱點內容
初學c語言顯示源未編譯 瀏覽:245
資產概況源碼 瀏覽:472
dos命令建文件夾命令 瀏覽:378
解壓的密碼htm被屏蔽 瀏覽:502
冬天太冷冰箱壓縮機不啟動怎麼辦 瀏覽:83
手機打開vcf需要什麼編譯器 瀏覽:910
加密磁碟後開機很慢 瀏覽:271
長沙智能雲控系統源碼 瀏覽:258
阿里雲伺服器如何設置操作系統 瀏覽:999
超級命令的英文 瀏覽:783
做賬為什麼要用加密狗 瀏覽:586
考研群體怎麼解壓 瀏覽:159
linux修改命令提示符 瀏覽:226
圓圈裡面k圖標是什麼app 瀏覽:63
pdf加空白頁 瀏覽:948
linux伺服器如何看網卡狀態 瀏覽:318
解壓新奇特視頻 瀏覽:707
圖書信息管理系統java 瀏覽:554
各種直線命令詳解 瀏覽:864
程序員淚奔 瀏覽:147