导航:首页 > 编程语言 > 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相关的资料

热点内容
做账为什么要用加密狗 浏览:583
考研群体怎么解压 浏览:156
linux修改命令提示符 浏览:224
圆圈里面k图标是什么app 浏览:59
pdf加空白页 浏览:945
linux服务器如何看网卡状态 浏览:316
解压新奇特视频 浏览:704
图书信息管理系统java 浏览:552
各种直线命令详解 浏览:862
程序员泪奔 浏览:146
素材怎么上传到服务器 浏览:515
android百度离线地图开发 浏览:189
web可视化编程软件 浏览:292
java笔试编程题 浏览:746
win11什么时候可以装安卓 浏览:564
java不写this 浏览:1001
云点播电影网php源码 浏览:97
pythonclass使用方法 浏览:226
移动加密软件去哪下载 浏览:294
php弹出alert 浏览:209