二、启动任务 start.jsp是web.xml部署描述符中声明的欢迎页面,web.xml的内容是:<?xml version="1.0" encoding="gb2312"?><!doctype web-app public "-//sun microsystems, inc.//dtd web application 2.3//en" "http://java.sun.com/dtd/web-app_2_3.dtd"><web-app> <welcome-file-list> <welcome-file>start.jsp</welcome-file> </welcome-file-list></web-app> start.jsp启动一个专用的线程来运行“繁重的任务”,然后把http请求传递给status.jsp。 start.jsp页...
如果任务已经启动,isstarted()方法将返回true:public synchronized boolean isstarted() { return started;} 如果任务已经完成,iscompleted()方法将返回true:public synchronized boolean iscompleted() { return counter == 100;} 如果任务正在运行,isrunning()方法将返回true:public synchronized boolean isrunning() { return running;} setrunning()方法由start.jsp或stop.jsp调用,当running参数是true时。setrunning()方法还要将任务标记为“已经启动”。调用setrunning(false)表示要求run()方法停止执行。pub...
许多web应用、企业应用涉及到长时间的操作,例如复杂的数据库查询或繁重的xml处理等,虽然这些任务主要由数据库系统或中间件完成,但任务执行的结果仍旧要借助jsp才能发送给用户。本文介绍了一种通过改进前端表现层来改善用户感觉、减轻服务器负载的办法。 当jsp调用一个必须长时间运行的操作,且该操作的结果不能(在服务器端)缓冲,用户每次请求该页面时都必须长时间等待。很多时候,用户会失去耐心,接着尝试点击浏览器的刷新按钮,最终失望地离开。 本文介绍的技术是把繁重的计算任务分离开来,由一个独立的线程运行,从而解决上述问题。当用户调用jsp页面时,jsp页面会立即返回,并提示用户任务已经启动且正在执行;jsp页面自动刷新自己,报告在独立线程中运行的繁重计算任务的当前进度,直至任务完成。一、模拟任务 首先我们设计一个taskbean类,它实现java.lang.runnable 接口,其run()方法在...
七、jsp连接postgresql数据库 testmysql.jsp如下: <%@ page contenttype="text/html;charset=gb2312"%> <%@ page import="java.sql.*"%> <html> <body> <%class.forname("org.postgresql.driver").newinstance(); string url ="jdbc:postgresql://localhost/soft" //soft为你的数据库名 string user="myuser"; string password="mypassword"; connection conn= drivermanager.getconnection(url,user,password); statement stmt=con...
六、jsp连接mysql数据库 testmysql.jsp如下: <%@ page contenttype="text/html;charset=gb2312"%> <%@ page import="java.sql.*"%> <html> <body> <%class.forname("org.gjt.mm.mysql.driver").newinstance(); string url ="jdbc:mysql://localhost/softforum?user=soft&password=soft1234&useunicode=true&characterencoding=8859_1" //testdb为你的数据库名 connection conn= drivermanager.getconnection(url); statement stmt=c...
五、jsp连接sybase数据库 testmysql.jsp如下: <%@ page contenttype="text/html;charset=gb2312"%> <%@ page import="java.sql.*"%> <html> <body> <%class.forname("com.sybase.jdbc.sybdriver").newinstance(); string url =" jdbc:sybase:tds:localhost:5007/tsdata"; //tsdata为你的数据库名 properties sysprops = system.getproperties(); sysprops.put("user","userid"); sysprops.put("password","user_password"); connect...
四、jsp连接informix数据库 testinformix.jsp如下: <%@ page contenttype="text/html;charset=gb2312"%> <%@ page import="java.sql.*"%> <html> <body> <%class.forname("com.informix.jdbc.ifxdriver").newinstance(); string url = "jdbc:informix-sqli://123.45.67.89:1533/testdb:informixserver=myserver; user=testuser;password=testpassword"; //testdb为你的数据库名 connection conn= drivermanager.getconnection(url);...
三、jsp连接db2数据库 testdb2.jsp如下: <%@ page contenttype="text/html;charset=gb2312"%> <%@ page import="java.sql.*"%> <html> <body> <%class.forname("com.ibm.db2.jdbc.app.db2driver ").newinstance(); string url="jdbc:db2://localhost:5000/sample"; //sample为你的数据库名 string user="admin"; string password=""; connection conn= drivermanager.getconnection(url,user,password); statement stmt=conn.create...
二、jsp连接sql server7.0/2000数据库 testsqlserver.jsp如下: <%@ page contenttype="text/html;charset=gb2312"%> <%@ page import="java.sql.*"%> <html> <body> <%class.forname("com.microsoft.jdbc.sqlserver.sqlserverdriver").newinstance(); string url="jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs"; //pubs为你的数据库的 string user="sa"; string password=""; connection conn= drivermanager.get...
现在有好多初学jsp的网友经常会问数据库怎么连接啊,怎么老出错啊?所以我集中的在这写篇文章供大家参考,其实这种把数据库逻辑全部放在jsp里未必是好的做法,但是有利于初学者学习,所以我就这样做了,当大家学到一定程度的时候,可以考虑用mvc的模式开发。在练习这些代码的时候,你一定将jdbc的驱动程序放到服务器的类路径里,然后要在数据库里建一个表test,有两个字段比如为test1,test2,可以用下面sql建 create table test(test1 varchar(20),test2 varchar(20)然后向这个表写入一条测试纪录,那么现在开始我们的jsp和数据库之旅吧。 一、jsp连接oracle8/8i/9i数据库(用thin模式) testoracle.jsp如下: <%@ page contenttype="text/html;charset=gb2312"%> &...
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器