java代码获取页签数 jsp获取java代码里的值

如何在java代码中获取页面内容

import java.io.BufferedReader;

10余年的根河网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网整合营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整根河建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“根河网站设计”,“根河网站推广”以来,每个客户项目都认真落实执行。

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;

}

}}

在获取到的页面内容是字符串,这里解析有两个办法,一是通过dom4j把字符串转化为dom进行解析,这样最好,但是对方的页面未必规范,符合dom结构。二是通过解析字符串过滤你想要的内容,该方法比较繁琐,需要一些技巧。我有的就是二;

谁能给我一个java分页标签的代码参考一下

下面的代码是纯jsp页面分页

也有java后台代码的分页,你如果想要的话就说。

%@ page contentType="text/html; charset=gb2312" %

%@ page language="java" %

%@ page import="java.sql.*" %

%

//驱动程序名,比较旧了,如果你用mysql5,自己改。

String driverName="org.gjt.mm.mysql.Driver";

String userName="root";//数据库用户名

String userPasswd="";//密码

String dbName="bookstore";//数据库名

String tableName="items"; //表名

//连接字符串

String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"password="+userPasswd;

Class.forName(driverName).newInstance();

Connection connection=DriverManager.getConnection(url);

Statement statement = connection.createStatement();

//每页显示记录数

int PageSize = 8;

int StartRow = 0; //开始显示记录的编号

int PageNo=0;//需要显示的页数

int CounterStart=0;//每页页码的初始值

int CounterEnd=0;//显示页码的最大值

int RecordCount=0;//总记录数;

int MaxPage=0;//总页数

int PrevStart=0;//前一页

int NextPage=0;//下一页

int LastRec=0;

int LastStartRecord=0;//最后一页开始显示记录的编号

//获取需要显示的页数,由用户提交

if(request.getParameter("PageNo")==null){ //如果为空,则表示第1页

if(StartRow == 0){

PageNo = StartRow + 1; //设定为1

}

}else{

PageNo = Integer.parseInt(request.getParameter("PageNo")); //获得用户提交的页数

StartRow = (PageNo - 1) * PageSize; //获得开始显示的记录编号

}

//设置显示页码的初始值

if(PageNo % PageSize == 0){

CounterStart = PageNo - (PageSize - 1);

}else{

CounterStart = PageNo - (PageNo % PageSize) + 1;

}

CounterEnd = CounterStart + (PageSize - 1);

%

html

head

title分页显示记录/title

link rel="stylesheet" href="style.css" type="text/css"

/head

%

//获取总记录数

ResultSet rs = statement.executeQuery("select count(*) from items" );

rs.next();

RecordCount = rs.getInt(1);

rs = statement.executeQuery("SELECT image_url,author,price,item_id FROM items ORDER BY item_id DESC LIMIT "

+StartRow+", "+PageSize);

//获取总页数

MaxPage = RecordCount % PageSize;

if(RecordCount % PageSize == 0){

MaxPage = RecordCount / PageSize;

}else{

MaxPage = RecordCount/PageSize+1;

}

%

body class="UsePageBg"

table width="100%" border="0" class="InternalHeader"

tr

td width="24%"font size=4分页显示记录/font/td

td width="76%"

font size=4%="总共"+RecordCount+"条记录 - 当前页:"+PageNo+"/"+MaxPage %/font

/td

/tr

/table

br

table width="100%" border="0" class="NormalTableTwo"

tr

td class="InternalHeader"记录序号/td

td class="InternalHeader" 图像路径/td

td class="InternalHeader" 作者/td

td class="InternalHeader" 价格/td

td class="InternalHeader" 图书编号/td

/tr

%

int i = 1;

while (rs.next()) {

int bil = i + (PageNo-1)*PageSize;

%

tr

td class="NormalFieldTwo" %=bil %/td

td class="NormalFieldTwo" %=rs.getString(1)%/td

td class="NormalFieldTwo" %=rs.getString(2)%/td

td class="NormalFieldTwo" %=rs.getString(3)%/td

td class="NormalFieldTwo" %=rs.getString(4)%/td

/tr

%

i++;

}%

/table

br

table width="100%" border="0" class="InternalHeader"

tr

tddiv align="center"

%

out.print("font size=4");

//显示第一页或者前一页的链接

//如果当前页不是第1页,则显示第一页和前一页的链接

if(PageNo != 1){

PrevStart = PageNo - 1;

out.print("a href=TestPage.jsp?PageNo=1第一页 /a: ");

out.print("a href=TestPage.jsp?PageNo="+PrevStart+"前一页/a");

}

out.print("[");

//打印需要显示的页码

for(int c=CounterStart;c=CounterEnd;c++){

if(c MaxPage){

if(c == PageNo){

if(c %PageSize == 0){

out.print(c);

}else{

out.print(c+" ,");

}

}else if(c % PageSize == 0){

out.print("a href=TestPage.jsp?PageNo="+c+""+c+"/a");

}else{

out.print("a href=TestPage.jsp?PageNo="+c+""+c+"/a ,");

}

}else{

if(PageNo == MaxPage){

out.print(c);

break;

}else{

out.print("a href=TestPage.jsp?PageNo="+c+""+c+"/a");

break;

}

}

}

out.print("]");;

if(PageNo MaxPage){ //如果当前页不是最后一页,则显示下一页链接

NextPage = PageNo + 1;

out.print("a href=TestPage.jsp?PageNo="+NextPage+"下一页/a");

}

//同时如果当前页不是最后一页,要显示最后一页的链接

if(PageNo MaxPage){

LastRec = RecordCount % PageSize;

if(LastRec == 0){

LastStartRecord = RecordCount - PageSize;

}

else{

LastStartRecord = RecordCount - LastRec;

}

out.print(":");

out.print("a href=TestPage.jsp?PageNo="+MaxPage+"最后一页/a");

}

out.print("/font");

%

/div

/td

/tr

/table

%

rs.close();

statement.close();

connection.close();

%

/body

/html

java poi怎么获取Excel sheet页的数量?

java poi获取Excel sheet页的数量方法如下:

在导出excel时候需要导出多个sheet页,后面sheet页会覆盖前面sheet页的内容。

这么写代码:

HSSFWorkbook workbook = null;

workbook=new HSSFWorkbook();

for(){

//没有现成的文件需要重新计算

HSSFSheet sheet_sin =workbook.createSheet(month_query1);

sheet_sin= makeJDL(year_query,month_query1,sheet_sin,workbook);

}

JAVA中想用正则表达式匹配获取下面的页码数,求问应该怎么写?

String s = "a href=\"?tid-21.htmlpage=2\"2/a";

System.out.println(s.replaceAll("^.*page=", "").replaceAll("\".*$", ""));

System.out.println(s.replaceAll("(^.*\")|/.*$", ""));

jsp页面java代码如何获取本页面的参数

假设这JSP叫 index.jsp,自己提交给自己.

%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%

html

body

form id="test" method="post" action="index.jsp"

select id="code"  name="plugin"

option value="1cn"cn/option

option value="2us"us/option

option value="3en"en/option

/select

input type="submit" value="提交"

br

%out.println(request.getParameter("plugin")); %

/form

/body

/html

请采纳.


新闻名称:java代码获取页签数 jsp获取java代码里的值
文章转载:http://myzitong.com/article/hepdho.html