javaipage的简单介绍
本篇文章给大家谈谈javaipage,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、java的分页
- 2、java 如何分页
- 3、java中如何判断web工程中图片的绝对路径是否存在
- 4、java中action如何获得客户端文件的路径
- 5、JAVA WEB 分页
- 6、开源里有没有留言板的源代码,JAVA的
java的分页
this.sqlStr=sqlStr+"limit"+irows+","+pageSize;
这句是:sqlStr 是用来存放你的SQL语句的变量;整个的意思就是:
比如:sqlStr="select * from user";
this.sqlStr="select * from user limit 9,4
就是查询表user 数据从第九行开始,向后查4行。每页显示4行数据。
String[] sData = new String[6]; 定义一个大小为6的字符串数组,
for(int j=0;jrsmd.getColumnCount();j++){*******************getColumnCount()什么意思有啥用????
sData[j]=rs.getString(j+1);
}
这句是循环遍历,将数据库的数据循环遍历的赋给字符串数组。
亲,希望我的回答对你有帮助。
java 如何分页
分页你需要定义4个变量,信息总条数allCount,每页的信息条数pageSize,当前页curPage,总页数allPageCount,利用这4个变量即可以分页;
总页数allPageCount的算法allPageCount=(allCount-1)/pageSize+1;
然后再写分页的逻辑,首页即当前页为1,上一页下一页,末页即curPage=allPageSize,写上一页下一页的时候只要判断一下当前页与总页数的关系既可
总体思路是这样的,当然从数据库取出数据的时候要找出当前页面显示的信息
java中如何判断web工程中图片的绝对路径是否存在
1.基本概念的理解
绝对路径:绝对路径就是你的主页上的文件或目录在硬盘上真正的路径,(URL和物理路径)例如:
C:/xyz/test.txt 代表了test.txt文件的绝对路径。也代表了一个
URL绝对路径。
相对路径:相对与某个基准目录的路径。包含Web的相对路径(HTML中的相对目录),例如:在
Servlet中,"/"代表Web应用的跟目录。和物理路径的相对表示。例如:"./" 代表当前目录,
"../"代表上级目录。这种类似的表示,也是属于相对路径。
另外关于URI,URL,URN等内容,请参考RFC相关文档标准。
RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax,
()
2.关于JSP/Servlet中的相对路径和绝对路径。
2.1服务器端的地址
服务器端的相对地址指的是相对于你的web应用的地址,这个地址是在服务器端解析的
(不同于html和javascript中的相对地址,他们是由客户端浏览器解析的)也就是说这时候
在jsp和servlet中的相对地址应该是相对于你的web应用,即相对于的。
其用到的地方有:
forward:servlet中的request.getRequestDispatcher(address);这个address是
在服务器端解析的,所以,你要forward到a.jsp应该这么写:
request.getRequestDispatcher(“/user/a.jsp”)这个/相对于当前的web应用webapp,
其绝对地址就是:。
sendRedirect:在jsp中%response.sendRedirect("/rtccp/user/a.jsp");%
2.22、客户端的地址
所有的html页面中的相对地址都是相对于服务器根目录()的,
而不是(跟目录下的该Web应用的目录)的。
Html中的form表单的action属性的地址应该是相对于服务器根目录()的,
所以,如果提交到a.jsp为:action="/webapp/user/a.jsp"或action="%=request.getContextPath()%"/user/a.jsp;
提交到servlet为actiom="/webapp/handleservlet"
Javascript也是在客户端解析的,所以其相对路径和form表单一样。
因此,一般情况下,在JSP/HTML页面等引用的CSS,Javascript.Action等属性前面最好都加上
%=request.getContextPath()%,以确保所引用的文件都属于Web应用中的目录。
另外,应该尽量避免使用类似".","./","../../"等类似的相对该文件位置的相对路径,这样
当文件移动时,很容易出问题。
3. JSP/Servlet中获得当前应用的相对路径和绝对路径
3.1 JSP中获得当前应用的相对路径和绝对路径
根目录所对应的绝对路径:request.getRequestURI()
文件的绝对路径 :application.getRealPath(request.getRequestURI());
当前web应用的绝对路径 :application.getRealPath("/");
取得请求文件的上层目录:new File(application.getRealPath(request.getRequestURI())).getParent()
3.2 Servlet中获得当前应用的相对路径和绝对路径
根目录所对应的绝对路径:request.getServletPath();
文件的绝对路径 :request.getSession().getServletContext().getRealPath
(request.getRequestURI())
当前web应用的绝对路径 :servletConfig.getServletContext().getRealPath("/");
(ServletContext对象获得几种方式:
javax.servlet.http.HttpSession.getServletContext()
javax.servlet.jsp.PageContext.getServletContext()
javax.servlet.ServletConfig.getServletContext()
)
4.java 的Class中获得相对路径,绝对路径的方法
4.1单独的Java类中获得绝对路径
根据java.io.File的Doc文挡,可知:
默认情况下new File("/")代表的目录为:System.getProperty("user.dir")。
一下程序获得执行类的当前路径
package org.cheng.file;
import java.io.File;
public class FileTest {
public static void main(String[] args) throws Exception {
System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));
System.out.println(FileTest.class.getClassLoader().getResource(""));
System.out.println(ClassLoader.getSystemResource(""));
System.out.println(FileTest.class.getResource(""));
System.out.println(FileTest.class.getResource("/")); //Class文件所在路径
System.out.println(new File("/").getAbsolutePath());
System.out.println(System.getProperty("user.dir"));
}
}
4.2服务器中的Java类获得当前路径(来自网络)
(1).Weblogic
WebApplication的系统文件根目录是你的weblogic安装所在根目录。
例如:如果你的weblogic安装在c:/bea/weblogic700.....
那么,你的文件根路径就是c:/.
所以,有两种方式能够让你访问你的服务器端的文件:
a.使用绝对路径:
比如将你的参数文件放在c:/yourconfig/yourconf.properties,
直接使用 new FileInputStream("yourconfig/yourconf.properties");
b.使用相对路径:
相对路径的根目录就是你的webapplication的根路径,即WEB-INF的上一级目录,将你的参数文件放
在yourwebapp/yourconfig/yourconf.properties,
这样使用:
new FileInputStream("./yourconfig/yourconf.properties");
这两种方式均可,自己选择。
(2).Tomcat
在类中输出System.getProperty("user.dir");显示的是%Tomcat_Home%/bin
(3).Resin
不是你的JSP放的相对路径,是JSP引擎执行这个JSP编译成SERVLET
的路径为根.比如用新建文件法测试File f = new File("a.htm");
这个a.htm在resin的安装目录下
(4).如何读相对路径哪?
在Java文件中getResource或getResourceAsStream均可
例:getClass().getResourceAsStream(filePath);//filePath可以是"/filename",这里的/代表web
发布根路径下WEB-INF/classes
默认使用该方法的路径是:WEB-INF/classes。已经在Tomcat中测试。
5.读取文件时的相对路径,避免硬编码和绝对路径的使用。(来自网络)
5.1 采用Spring的DI机制获得文件,避免硬编码。
参考下面的连接内容:
;
5.2 配置文件的读取
参考下面的连接内容:
5.3 通过虚拟路径或相对路径读取一个xml文件,避免硬编码
参考下面的连接内容:
;tID=10708ccID=8
6.Java中文件的常用操作(复制,移动,删除,创建等)(来自网络)
常用 java File 操作类
Java文件操作大全(JSP中)
java文件操作详解(Java中文网)
JAVA 如何创建/删除/修改/复制目录及文件
总结:
通过上面内容的使用,可以解决在Web应用服务器端,移动文件,查找文件,复制
删除文件等操作,同时对服务器的相对地址,绝对地址概念更加清晰。
建议参考URI,的RFC标准文挡。同时对Java.io.File. Java.net.URI.等内容了解透彻
对其他方面的理解可以更加深入和透彻。
==================================================================================
参考资料:
java/docs/
java.io.File
java.io.InputStream
java.io.OutputStream
java.io.FileInputStream
java.io.FileReader;
java.io.FileOutputStream
java.io.FileWriter;
java.net.URI
java.net.URL
绝对路径与相对路径祥解
[『J道习练』]JSP和Servlet中的绝对路径和相对路径
;id=9122commentid=12376
JSP,Servlet,Class获得当前应用的相对路径和绝对路径
;tID=886ccID=77
如何获得当前文件路径
通过Spring注入机制,取得文件
;
配置文件的读取
读取配置文件,通过虚拟路径或相对路径读取一个xml文件,避免硬编码!
;tID=10708ccID=8
常用 java File 操作类
Java文件操作大全
Java文件操作详解
java中action如何获得客户端文件的路径
1.基本概念的理解 绝对路径: 绝对路径就是你的主页上的文件或目录在硬盘上真正的路径,( URL和物理路径)例如: C:\xyz\test.txt代表了test. txt文件的绝对路径。 index.htm也代表了一个 URL绝对路径。 相对路径:相对与某个基准目录的路径。包含Web的相对路径( HTML中的相对目录),例如:在 Servlet中,"/"代表Web应用的跟目录。 和物理路径的相对表示。例如:"./" 代表当前目录, "../"代表上级目录。这种类似的表示,也是属于相对路径。 另外关于URI,URL,URN等内容, 请参考RFC相关文档标准。 RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax, ( rfc2396.txt ) 2.关于JSP/Servlet中的相对路径和绝对路径。 2.1服务器端的地址 服务器端的相对地址指的是相对于你的web应用的地址, 这个地址是在服务器端解析的 (不同于html和javascript中的相对地址, 他们是由客户端浏览器解析的)也就是说这时候 在jsp和servlet中的相对地址应该是相对于你的web应 用,即相对于 webapp/的。 其用到的地方有: forward:servlet中的request. getRequestDispatcher(address); 这个address是 在服务器端解析的,所以,你要forward到a. jsp应该这么写: request.getRequestDispatcher(“ /user/a.jsp”)这个/ 相对于当前的web应用webapp, 其绝对地址就是: webapp/user/a.jsp。 sendRedirect:在jsp中%response. sendRedirect("/rtccp/user/a. jsp");% 2.22、客户端的地址 所有的html页面中的相对地址都是相对于服务器根目录( htt p://192.168.0.1/ )的, 而不是(跟目录下的该Web应用的目录) . 168.0.1/webapp/的 。 Html中的form表单的action属性的地址应该是相对于 服务器根目录( )的, 所以,如果提交到a.jsp为:action="/ webapp/user/a.jsp"或action="%= request.getContextPath()%"/ user/a.jsp; 提交到servlet为actiom="/webapp/ handleservlet" Javascript也是在客户端解析的, 所以其相对路径和form表单一样。 因此,一般情况下,在JSP/HTML页面等引用的CSS, Javascript.Action等属性前面最好都加上 %=request.getContextPath()%, 以确保所引用的文件都属于Web应用中的目录。 另外,应该尽量避免使用类似".","./","../../" 等类似的相对该文件位置的相对路径,这样 当文件移动时,很容易出问题。 3. JSP/Servlet中获得当前应用的相对路径和绝对路径 3.1 JSP中获得当前应用的相对路径和绝对路径 根目录所对应的绝对路径:request. getRequestURI() 文件的绝对路径 :application.getRealPath( request.getRequestURI()); 当前web应用的绝对路径 :application.getRealPath("/"); 取得请求文件的上层目录:new File(application.getRealPath( request.getRequestURI())). getParent() 3.2 Servlet中获得当前应用的相对路径和绝对路径 根目录所对应的绝对路径:request. getServletPath(); 文件的绝对路径 :request.getSession(). getServletContext(). getRealPath (request.getRequestURI()) 当前web应用的绝对路径 :servletConfig. getServletContext(). getRealPath("/"); (ServletContext对象获得几种方式: javax.servlet.http. HttpSession.getServletContext( ) javax.servlet.jsp. PageContext.getServletContext( ) javax.servlet. ServletConfig. getServletContext() ) 4.java 的Class中获得相对路径,绝对路径的方法 4.1单独的Java类中获得绝对路径 根据java.io.File的Doc文挡,可知: 默认情况下new File("/")代表的目录为:System. getProperty("user.dir")。 一下程序获得执行类的当前路径 package org.cheng.file; import java.io.File; public class FileTest { public static void main(String[] args) throws Exception { System.out.println(Thread. currentThread(). getContextClassLoader(). getResource("")); System.out.println(FileTest. class.getClassLoader(). getResource("")); System.out.println( ClassLoader.getSystemResource( "")); System.out.println(FileTest. class.getResource("")); System.out.println(FileTest. class.getResource("/")); //Class文件所在路径 System.out.println(new File("/").getAbsolutePath()); System.out.println(System. getProperty("user.dir")); } } 4.2服务器中的Java类获得当前路径(来自网络) (1).Weblogic WebApplication的系统文件根目录是你的weblo gic安装所在根目录。 例如:如果你的weblogic安装在c:\bea\ weblogic700..... 那么,你的文件根路径就是c:\. 所以,有两种方式能够让你访问你的服务器端的文件: a.使用绝对路径: 比如将你的参数文件放在c:\yourconfig\ yourconf.properties, 直接使用 new FileInputStream("yourconfig/ yourconf.properties"); b.使用相对路径: 相对路径的根目录就是你的webapplication的根路径 ,即WEB-INF的上一级目录,将你的参数文件放 在yourwebapp\yourconfig\ yourconf.properties, 这样使用: new FileInputStream("./yourconfig/ yourconf.properties"); 这两种方式均可,自己选择。 (2).Tomcat 在类中输出System.getProperty("user. dir");显示的是%Tomcat_Home%/bin (3).Resin 不是你的JSP放的相对路径, 是JSP引擎执行这个JSP编译成SERVLET 的路径为根.比如用新建文件法测试File f = new File("a.htm"); 这个a.htm在resin的安装目录下 (4).如何读相对路径哪? 在Java文件中getResource或getResourc eAsStream均可 例:getClass(). getResourceAsStream(filePath); //filePath可以是"/filename",这里的/ 代表web 发布根路径下WEB-INF/classes 默认使用该方法的路径是:WEB-INF/classes。 已经在Tomcat中测试。 5.读取文件时的相对路径,避免硬编码和绝对路径的使用。( 来自网络) 5.1 采用Spring的DI机制获得文件,避免硬编码。 参考下面的连接内容: viewtopic.php?p=90213 5.2 配置文件的读取 参考下面的连接内容: article/39/39681.shtm 5.3 通过虚拟路径或相对路径读取一个xml文件,避免硬编码 参考下面的连接内容: clubPage.jsp?iPage=1tID= 10708ccID=8 6.Java中文件的常用操作(复制,移动,删除,创建等)( 来自网络) 常用 java File 操作类 200604022353065155.htm Java文件操作大全(JSP中) pcedu/empolder/gj/java/0502/ 559401.html java文件操作详解(Java中文网) 2005/1108/10947.htm JAVA 如何创建\删除\修改\复制目录及文件 developer/java/2005/2/264.html 总结: 通过上面内容的使用,可以解决在Web应用服务器端, 移动文件,查找文件,复制 删除文件等操作,同时对服务器的相对地址, 绝对地址概念更加清晰。 建议参考URI,的RFC标准文挡。同时对Java.io. File. Java.net.URI.等内容了解透彻 对其他方面的理解可以更加深入和透彻。
JAVA WEB 分页
这是我自己写的,不知道对lz有没有用
分页包括3个类Page.java,PageService.java,PageSizeConfig.java
一个接口:PageDAO
一个配置文件:page.xml
下面是源码:(比较懒,没有写注释)
Page.java
public class Page {
public int pageSize; //页面大小
private int rowSize;//数据总数
private int pageConut;//页数
private int page;//当前页数
public Page(int rowSize,int page,int pageSize)
{
this.rowSize=rowSize;
this.pageSize=pageSize;
pageConut=(rowSize-1)/pageSize+1;
this.page=page;
}
public int getRowSize() {
return rowSize;
}
public void setRowSize(int rowSize) {
this.rowSize = rowSize;
pageConut=(rowSize-1)/pageSize+1;
}
public int getPageConut() {
return pageConut;
}
public void setPageConut(int pageConut) {
this.pageConut = pageConut;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
//首页
public void first()
{
page=1;
}
//末页
public void last()
{
page=pageConut;
}
//下一页
public void next()
{
page++;
if(pagepageConut)
{
page=pageConut;
}
}
//上一页
public void previous()
{
page--;
if(page1)
{
page=1;
}
}
//转到第currentPage页
public void go(int currentPage)
{
page=currentPage;
if(page1)
{
page=1;
}
if(pagepageConut)
{
page=pageConut;
}
}
/**
* 获取"下一页"的可用状态
* 返回空表示不可用,相反则可用
* @return
*/
public String getNext()
{
if(pagepageConut)
{
return "next";
}
return "";
}
/**
* 获取"上一页"的可用状态
* 返回空表示不可用,相反则可用
* @return
*/
public String getPrevious()
{
if(page1)
{
return "previous";
}
return "";
}
public int getPageSize() {
return pageSize;
}
}
PageServise.java
public class PageService {
public static void service(HttpServletRequest request,PageDAO dao,String session)
{
int pageSize=PageSizeConfig.pageSize(dao.getClass().getName());
String pageAction=request.getParameter("pageAction");
Page p=(Page)request.getSession().getAttribute(session);
if(p==null)
{
p=new Page(dao.getRowCount(),1,pageSize);
System.out.println("count="+dao.getRowCount());
}
else
{
p.setRowSize(dao.getRowCount());
}
if(pageAction==null)
{
return;
}
if("first".equals(pageAction))
{
p.first();
}
else if ("last".equals(pageAction))
{
p.last();
}
else if("next".equals(pageAction))
{
p.next();
}
else if("previous".equals(pageAction))
{
p.previous();
}
else if("go".equals(pageAction))
{
int currentPage=Integer.parseInt(request.getParameter("currentPage"));
p.go(currentPage);
}
request.getSession().setAttribute(session, p);
int start=(p.getPage()-1)*pageSize;
List list=dao.getDataList(start, pageSize);
request.setAttribute("list", list);
ListInteger pageList=new ArrayListInteger();
for(int i=1;i=p.getPageConut();i++)
{
pageList.add(new Integer(i));
}
request.setAttribute("pageList", pageList);
}
}
PageSizeConfig.java
public class PageSizeConfig {
public static final int DEFAULT_PAGE_SIZE=5;
private static MapString,Integer map;
static
{
load();
}
private static void load()
{
map=new HashMapString,Integer();
try {
InputStream is=Thread.currentThread().getContextClassLoader().getResourceAsStream("com/shop/page/page.xml");
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder bulider=factory.newDocumentBuilder();
Document doc=bulider.parse(is);
NodeList nl=doc.getElementsByTagName("size");
for(int i=0;inl.getLength();i++)
{
Node node=nl.item(i);
String type=node.getAttributes().item(0).getFirstChild().getNodeValue();
int size=Integer.parseInt(node.getTextContent());
map.put(type, new Integer(size));
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static int pageSize(String className)
{
if(map.containsKey(className))
{
return map.get(className);
}
return DEFAULT_PAGE_SIZE;
}
}
PageDAO.java
package com.shop.page;
import java.util.List;
public interface PageDAOT {
int getRowCount();
ListT getDataList(int start,int pageSize);
}
page.xml
?xml version="1.0" encoding="UTF-8"?
page-config
size type="com.shop.page.impl.SearchGoodPageImpl"20/size
/page-config
我觉得有点不好的就是每个需要分页的地方都要创建一个session
如果lz觉得有用,email我:icewater506@yahoo.com.cn
开源里有没有留言板的源代码,JAVA的
绝对开源,绝对明了的留言板,便于学习的源码
用JAVA写的留言板原代码
/*
* guestbookServlet.java
*
* */
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.Date;
/**
*
* */
public class guestbookServlet extends HttpServlet {
boolean debug=false;
String sDBDriver;
Connection conn=null;
ResultSet rs=null;
/** Initializes the servlet.
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
if(debug)
sDBDriver=new String("sun.jdbc.odbc.JdbcOdbcDriver");
else
sDBDriver=new String("org.gjt.mm.mysql.Driver");
try{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e){
System.err.println("Driver类初始化:"+e.getMessage());
}
}
/** Destroys the servlet.
*/
public void destroy() {
}
/** Processes requests for both HTTP codeGET/code and codePOST/code methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
response.setContentType("text/html;charset=gb2312");
java.io.PrintWriter out = response.getWriter();
boolean empty=true;
boolean noResult=true;
String sqlStr;
int currentPage=0;
int totalPage=0;
int reccount=0;
ResultSet myrs=null;
String username=request.getParameter("username");
String email=request.getParameter("email");
String ucontent=request.getParameter("ucontent");
String ipage=request.getParameter("ipage");
if(ipage==null||ipage.length()==0)
currentPage=1;
else
currentPage=Integer.parseInt(ipage);
if((username==null||username.length()==0)||(ucontent==null||ucontent.length()==0))empty=true;
else empty=false;
Date myDate=new Date();
//String intime=new String(String.valueOf(myDate.getYear()+1990)+String.valueOf(myDate.getMonth()));
String year=String.valueOf(myDate.getYear()+1900);
String month=String.valueOf(myDate.getMonth()+1);
if(month.length()==1)
month=new String("0"+month);
String days=String.valueOf(myDate.getDate());
if(days.length()==1)
days=new String("0"+days);
String hours=String.valueOf(myDate.getHours());
if(hours.length()==1)
hours=new String("0"+hours);
String minutes=String.valueOf(myDate.getMinutes());
if(minutes.length()==1)
minutes=new String("0"+minutes);
String intime=year+"-"+month+"-"+days+" "+hours+":"+minutes;
if(email==null||email.length()==0)
email=new String("");
if(!empty){
//username=convert(username);
//email=convert(email);
//ucontent=convert(ucontent);
sqlStr="insert into Mintegbook(Mname,Memail,Mcontent,Mtime,Mid) values("+username+","+email+","+ucontent+","+intime+",1)";
getDsnConn();
executeInsert(sqlStr);
}
sqlStr=new String("select Mname,Memail,Mcontent,Mtime from Mintegbook order by Mtime DESC");
getDsnConn();
reccount=getRecordCount("Mintegbook");
if(reccount==0)
noResult=true;
else
noResult=false;
if(!noResult){
int ipageSize=10;
totalPage=getTotalPage("Mintegbook",ipageSize);
if(currentPagetotalPage)
currentPage=totalPage;
int cursor=(currentPage-1)*ipageSize+1;
try{
myrs=executeScrollableQuery(sqlStr);
myrs.absolute(cursor);
}
catch(SQLException e){
noResult=true;
}
}
out.println("HTMLHEADTITLE我的Servlet留言板/TITLE");
out.println("META http-equiv="Content-Type" content="text/html; charset=gb2312"");
out.println("STYLE type="text/css"");
out.println("!--");
out.println(".mytext { font-family: "宋体"; font-size: 12px}");
out.println(" --");
out.println("/STYLE");
out.println("/HEAD");
out.println("BODY bgcolor="#FFFFFF" text="#000000"");
out.println("TABLE width="600" border="0" cellspacing="0" cellpadding="0" align="CENTER" class="mytext"");
out.println("TRTD height="22" | a href=""我的主页/a | 我的Servlet留言板(A href="mailto:yf188@21cn.com"川石/A制作)/TD/TR");
out.println("TRTD height="1" bgcolor="#999933"/TD/TR");
out.println("/TABLE");
out.println("BR");
out.println("TABLE width="600" border="0" cellspacing="0" cellpadding="0" align="CENTER" class="mytext"");
out.println("TRTD height="8"/TD/TR");
out.println("TRTD height="18" bgcolor="#f7f7f7"DIV align="right"");
out.println("共有 "+reccount + " 条留言 ");
out.println(" 当前第font color=#ff0000"+currentPage+"/font/共 "+totalPage+" 页 ");
if(currentPage1)
out.println(" a href=guestbookServlet?ipage=1首页/a a href=guestbookServlet?ipage="+(currentPage-1)+"上一页/a ");
else
out.println(" 首页 上一页 ");
if(currentPagetotalPage)
out.println(" a href=guestbookServlet?ipage="+(currentPage+1)+"下一页/a a href=guestbookServlet?ipage="+totalPage+"末页/a ");
else
out.println(" 下一页 末页 ");
out.println("/DIV/TD/TR");
out.println("/TABLE");
out.println("BR");
//这里是显示留言内容
if(!noResult){
String dname;
String demail;
String dcontent;
String dtime;
Date temptime;
try{
do{
dname=new String(myrs.getString("Mname"));
demail=new String(myrs.getString("Memail"));
dcontent=new String(myrs.getString("Mcontent"));
try{
dtime=new String(myrs.getObject("Mtime").toString());
}
catch(java.lang.NullPointerException e){
dtime=new String("2001-04-06 12:30");
}
if(dname==null)
dname=new String("川石");
if(demail==null)
demail=new String("yf188@21cn.com");
if(dcontent==null)
dcontent=new String("test");
if(dtime==null)
dtime=new String("2001-04-06 12:30");
dname=convert(dname);
dcontent=convert(dcontent);
//temptime=myrs.getDate("Mtime");
/*
String tempyear=String.valueOf(temptime.getYear()+1900);
String tempmonth=String.valueOf(temptime.getMonth()+1);
if(tempmonth.length()==1)
tempmonth=new String("0"+tempmonth);
String tempdays=String.valueOf(temptime.getDate());
if(tempdays.length()==1)
tempdays=new String("0"+tempdays);
String tempminute=String.valueOf(temptime.getMinutes());
if(tempminute.length()==1)
tempminute=new String("0"+tempminute);
String temphours=String.valueOf(temptime.getHours());
if(temphours.length()==1)
temphours=new String("0"+temphours);
String dtime=tempyear+" 年 "+ tempmonth +" 月 "+ tempdays +" 日 " + temphours+ " 时 "+ tempminute + " 分 ";
*/
out.println("TABLE width="600" border="0" cellspacing="0" cellpadding="4" align="CENTER" class="mytext"");
out.println("TRTD姓名 A href="mailto:"+demail+"""+dname+"/A 留言时间:"+dtime+"/TD/TR");
out.println("TRTD height="10"/TD/TR");
out.println("TRTD height="10""+dcontent+"/TD/TR");
out.println("/TABLE");
out.println("HR width="600" size="1"");
}while(myrs.next());}
catch(SQLException e){
out.println("error found");
}
}
else{
out.println("还没有留言!");
}
//结束
out.println("FORM name="form1" method="post" action="guestbookServlet"");
out.println("TABLE width="600" border="0" cellspacing="0" cellpadding="4" align="CENTER" class="mytext"");
out.println("TRTD width="80"姓名:/TDTDINPUT type="text" name="username"*/TD/TR");
out.println("TRTDEmail:/TDTDINPUT type="text" name="email"*/TD/TR");
out.println("TRTD留言:/TDTDTEXTAREA name="ucontent" cols="65" rows="4"/TEXTAREA/TD/TR");
out.println("/TABLE");
out.println("TABLE width="400" border="0" cellspacing="0" cellpadding="6" align="CENTER" class="mytext"");
out.println("TRTD height="15" width="200" /TDTD /TD/TR");
out.println("TRTDDIV align="RIGHT"INPUT type="button" name="Button" value=" 提 交 " style="cursor:hand" onclick="javascript:check()"/DIV/TD");
out.println("TDINPUT type="reset" name="Submit2" value=" 重 置 "/TD/TR");
out.println("/TABLE");
out.println("/FORM");
out.println("TABLE width="400" border="0" cellspacing="0" cellpadding="4" align="CENTER" class="mytext"");
out.println("TRTD width="15" /TD/TR");
out.println("TRTDDIV align="LEFT"/DIV/TD/TR");
out.println("TRTD /TD/TR");
out.println("/TABLE");
out.println("/BODY");
out.println("/HTML");
out.println("SCRIPT language="javascript"");
out.println("function check(){");
out.println("if(form1.username.value.length1||form1.ucontent.value.length1)");
out.println("{alert(姓名和留言是必须有的!);}else{form1.submit();}}");
out.println("/SCRIPT");
out.close();
}
/** Handles the HTTP codeGET/code method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
processRequest(request, response);
}
/** Handles the HTTP codePOST/code method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
processRequest(request, response);
}
protected void getDsnConn(){
String sqlUrl="jdbc:mysql://10.0.0.1/你申请用户名?user=你的名字password=你的帐号";
try{
if(debug)
conn=DriverManager.getConnection("jdbc:odbc:ODBC源","用户名","密码口令");
else
conn=DriverManager.getConnection(sqlUrl);
}
catch(SQLException es){
System.err.println("和库连接时出错:"+es.getMessage());
}
}
protected void executeInsert(String sqlStr){
try{
Statement stmt=conn.createStatement();
stmt.executeUpdate(sqlStr);
}
catch(SQLException es){
System.err.println("执行插入时:"+es.getMessage());
}
}
protected void executeUpdate(String sqlStr){
try{
Statement stmt=conn.createStatement();
stmt.executeUpdate(sqlStr);
}
catch(SQLException e){
System.err.println("error in query record");
}
}
//查寻
protected ResultSet executeQuery(String sqlStr){
rs=null;
try{
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(sqlStr);
}
catch(SQLException ex){
System.err.println("执行查寻出错:"+ex.getMessage());
}
return rs;
}
protected ResultSet executeScrollableQuery(String sqlStr){
rs=null;
try{
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery(sqlStr);
}
catch(SQLException e){
System.err.println("执行动态查寻出错");
}
return rs;
}
//得到表记录总数
protected int getRecordCount(String sTableName){
rs=null;
int CountResult=0;
String sqlStr="select count(*) from "+sTableName;
try{
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(sqlStr);
if(rs.next())
CountResult=rs.getInt(1);
rs=null;
stmt.close();
}
catch(SQLException ex){
System.err.println(ex.getMessage());
}
return CountResult;
}
//得到记录总页数
protected int getTotalPage(String sTableName,int iPageSize){
int totalPage;
int totalRecNum=getRecordCount(sTableName);
if(totalRecNum%iPageSize==0)
totalPage=totalRecNum/iPageSize;
else
totalPage=totalRecNum/iPageSize+1;
return totalPage;
}
protected String convert(String InputStr){
String converted=new String();
byte[] bytes;
try{
bytes=InputStr.getBytes("ISO8859-1");
converted=new String(bytes,"GB2312");
}
catch(java.io.UnsupportedEncodingException e){
System.out.print("error");
}
return converted;
}
/** Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Short description";
}
}
javaipage的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、javaipage的信息别忘了在本站进行查找喔。