导航:首页 > 编程语言 > javahtml表格

javahtml表格

发布时间:2022-07-09 02:42:16

java如何读取html页面的表单

实现代码:
<formaction="input.do"name="formkk">
<table>
<tbody>
<tr>

<td>text:</td>
<td>
<inputtype="text"name="text">
</td>
</tr>
<tr>

<td>password:</td>
<td>
<inputtype="password"name="pass">
</td>
</tr>
<tr>

<td>radio:</td>
<td>
<inputtype="radio"name="xingbie"value="1">

<inputtype="radio"name="xingbie"value="2">

</td>
</tr>
<tr>
<td>checkbox:</td>
<td>
足球:<inputtype="checkbox"name="hobby"value="1"/>
篮球:<inputtype="checkbox"name="hobby"value="2"/>
拍球:<inputtype="checkbox"name="hobby"value="3"/>
斗球:<inputtype="checkbox"name="hobby"value="4"/>
</td>
</tr>
<tr>
<td>hidden:</td>
<td>
<inputtype="hidden"value="123"name="hidden"/>
</td>
</tr>
<tr>
<td>option:</td>
<td>
<selectname="opt"id="opt">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>

</td>
</tbody>
</table>
<inputtype="button"value="提交"onclick="javascript:check()"/>
</form>
String[]hobbys=request.getParameterValues("hobby");//checkbox
Stringtext=request.getParameter("text");//text
Stringpassword=request.getParameter("password");//password
Stringxingbie=request.getParameter("xingbie");//radio
request.getParameter("hidden");
request.getParameter("opt");//select

❷ java 如何将html(包含表格,图片)转换为word

你用IE浏览器打开你的HTML文件,然后点击菜单栏 文件→使用 Microsoft Office Word 编辑,之后系统会自动打开 Word 并显示HTML文件的内容,这是保存即可。

如果找不到“使用 Microsoft Office Word 编辑”的话,点击菜单栏 工具→Internet 选项→程序→ HTML 编辑器 → Microsoft Office Word → 确定。

❸ java怎样读取html文件

java读取html文件跟读取普通文件一样,都是使用输入输出流,但是java读取html文件之后还需要解析,使用Jsoup对html进行解析。下面是一个java读取带表格的任意html文件,并把html文件转换成excel的例子。

要求:要求能够实现给出任意带table表格的html文件,生成与表格相同内容的excel文件,附件可以作为测试文件,提供给定的roster.html文件,通过java代码,实现生成与html页面的table相同样式的roster.xls文件。

首先看roster.html:

importjava.io.BufferedReader;
importjava.io.File;
importjava.io.FileReader;
importjava.io.IOException;
importjxl.Workbook;
importjxl.write.Label;
importjxl.write.WritableCellFormat;
importjxl.write.WritableFont;
importjxl.write.WritableSheet;
importjxl.write.WritableWorkbook;
importjxl.write.WriteException;
importjxl.write.biff.RowsExceededException;
importorg.jsoup.Jsoup;
importorg.jsoup.nodes.Document;
importorg.jsoup.nodes.Element;
importorg.jsoup.select.Elements;
publicclassHTMLTOExcel{
publicstaticvoidmain(Stringargs[])throwsIOException{
///读取classpath目录下面的路径
Stringpath=HTMLTOExcel.class.getResource("/").getPath();
path+="roster.html";
toExcel(path,"roster");
}
//得到Document并且设置编码格式
publicstaticDocumentgetDoc(StringfileName)throwsIOException{
FilemyFile=newFile(fileName);
Documentdoc=Jsoup.parse(myFile,"GBK","");
returndoc;
}
///这个方法用于根据trs行数和sheet画出整个表格
publicstaticvoidmergeColRow(Elementstrs,WritableSheetsheet)throwsRowsExceededException,WriteException{
int[][]rowhb=newint[300][50];
for(inti=0;i<trs.size();i++){
Elementtr=trs.get(i);
Elementstds=tr.getElementsByTag("td");

intrealColNum=0;
for(intj=0;j<tds.size();j++){
Elementtd=tds.get(j);
if(rowhb[i][realColNum]!=0){
realColNum=getRealColNum(rowhb,i,realColNum);
}
introwspan=1;
intcolspan=1;
if(td.attr("rowspan")!=""){
rowspan=Integer.parseInt(td.attr("rowspan"));
}
if(td.attr("colspan")!=""){
colspan=Integer.parseInt(td.attr("colspan"));
}
Stringtext=td.text();
drawMegerCell(rowspan,colspan,sheet,realColNum,i,text,rowhb);
realColNum=realColNum+colspan;
}

}
}
///这个方法用于根据样式画出单元格,并且根据rowpan和colspan合并单元格
publicstaticvoiddrawMegerCell(introwspan,intcolspan,WritableSheetsheet,intrealColNum,intrealRowNum,Stringtext,int[][]rowhb)throwsRowsExceededException,WriteException{
for(inti=0;i<rowspan;i++){
for(intj=0;j<colspan;j++){
if(i!=0||j!=0){
text="";
}
Labellabel=newLabel(realColNum+j,realRowNum+i,text);
WritableFontcountents=newWritableFont(WritableFont.TIMES,10);//设置单元格内容,字号12
WritableCellFormatcellf=newWritableCellFormat(countents);
cellf.setAlignment(jxl.format.Alignment.CENTRE);//把水平对齐方式指定为居中
cellf.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);//把垂直对齐方式指定为居
label.setCellFormat(cellf);
sheet.addCell(label);
rowhb[realRowNum+i][realColNum+j]=1;
}
}
sheet.mergeCells(realColNum,realRowNum,realColNum+colspan-1,realRowNum+rowspan-1);
}
publicstaticintgetRealColNum(int[][]rowhb,inti,intrealColNum){
while(rowhb[i][realColNum]!=0){
realColNum++;
}
returnrealColNum;
}
///根据colgroups设置表格的列宽
publicstaticvoidsetColWidth(Elementscolgroups,WritableSheetsheet){
if(colgroups.size()>0){
Elementcolgroup=colgroups.get(0);
Elementscols=colgroup.getElementsByTag("col");
for(inti=0;i<cols.size();i++){
Elementcol=cols.get(i);
Stringstrwd=col.attr("width");
if(col.attr("width")!=""){
intwd=Integer.parseInt(strwd);
sheet.setColumnView(i,wd/8);
}

}

}
}
//toExcel是根据html文件地址生成对应的xls
publicstaticvoidtoExcel(StringfileName,StringexcelName)throwsIOException{
Documentdoc=getDoc(fileName);
Stringtitle=doc.title();
///得到样式,以后可以根据正则表达式解析css,暂且没有找到cssparse
Elementsstyle=doc.getElementsByTag("style");
///得到Table,demo只演示输入一个table,以后可以用循环遍历tables集合输入所有table
Elementstables=doc.getElementsByTag("TABLE");
if(tables.size()==0){
return;
}
Elementtable=tables.get(0);
//得到所有行
Elementstrs=table.getElementsByTag("tr");
///得到列宽集合
Elementscolgroups=table.getElementsByTag("colgroup");

try{
//文件保存到classpath目录下面
Stringpath=HTMLTOExcel.class.getResource("/").getPath();
path+=excelName+".xls";
System.out.println(path);
WritableWorkbookbook=Workbook.createWorkbook(newFile(path));
WritableSheetsheet=book.createSheet("人事关系",0);
setColWidth(colgroups,sheet);
mergeColRow(trs,sheet);
book.write();
book.close();
}catch(RowsExceededExceptione){
e.printStackTrace();
}catch(WriteExceptione){
e.printStackTrace();
}
}
}

解析html文件的例子文档地址:http://blog.csdn.net/androidwuyou/article/details/52636821

❹ java 怎样获取一个网页的内容 要网页里面的表格数据 (通过源码不能直接获取数据),请教

根据java网络编程相关的内容,使用jdk提供的相关类可以得到url对应网页的html页面代码。
针对得到的html代码,通过使用正则表达式即可得到我们想要的内容。

比如,我们如果想得到一个网页上所有包括“java”关键字的文本内容,就可以逐行对网页代码进行正则表达式的匹配。最后达到去除html标签和不相关的内容,只得到包括“java”这个关键字的内容的效果。

从网页上爬取图片的流程和爬取内容的流程基本相同,但是爬取图片的步骤会多一步。

需要先用img标签的正则表达式匹配获取到img标签,再用src属性的正则表达式获取这个img标签中的src属性的图片url,然后再通过缓冲输入流对象读取到这个图片url的图片信息,配合文件输出流将读到的图片信息写入到本地即可。

❺ 怎么用java 生成html表单

out.println("<BODY>");
都使用out.println("xxx");这一句输出就可以了。

❻ 如何用Java爬虫方法以html的形式爬取一个网页上的表格

jsoup 支持html完整解析,如果使用httprequest,原生的话需要自己解析xml,通过httpconnection。

❼ 在Java中如何将html中的table列表解析出来

使用js中间的document.getElementById函数可以获取对应的html元素,document.getElementById().value就是对应元素的值

阅读全文

与javahtml表格相关的资料

热点内容
自己购买云主服务器推荐 浏览:419
个人所得税java 浏览:760
多余的服务器滑道还有什么用 浏览:189
pdf劈开合并 浏览:26
不能修改的pdf 浏览:750
同城公众源码 浏览:488
一个服务器2个端口怎么映射 浏览:297
java字符串ascii码 浏览:78
台湾云服务器怎么租服务器 浏览:475
旅游手机网站源码 浏览:332
android关联表 浏览:945
安卓导航无声音怎么维修 浏览:332
app怎么装视频 浏览:430
安卓系统下的软件怎么移到桌面 浏览:96
windows拷贝到linux 浏览:772
mdr软件解压和别人不一样 浏览:904
单片机串行通信有什么好处 浏览:340
游戏开发程序员书籍 浏览:860
pdf中图片修改 浏览:288
汇编编译后 浏览:491