首页 > 编程知识 正文

jsp主页框架代码,jsp网站开发详解

时间:2024-03-07 18:23:32 阅读:331990 作者:QREU

本文目录一览:

jsp 中网站的首页源代码

这是最简单的一个例子,数据库要你自己建,用的是ACCESS

%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %

html

head

meta http-equiv="Content-Type" content="text/html; charset=gb2312"

titleJSP连接Access数据库/title

style type="text/css"

!--

.style1 {

font-size: 20px;

font-weight: bold;

}

--

/style

/headbody

div align="center" class="style1"JSP连接Access数据库/div

br

hr

p%

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //载入驱动程序类别

Connection con = DriverManager.getConnection("jdbc:odbc:jspdata"); //建立数据库链接,jspdata为ODBC数据源名称

//建立Statement对象

Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_READ_ONLY);

ResultSet rs = stmt.executeQuery("select * from lyb"); //建立ResultSet(结果集)对象,并执行SQL语句

%

/p

p align="center"NUMB1数据表中记录如下/p

table width="640" border="1" align="center" bordercolor="#7188e0"

tr bgcolor="d1d1ff"

th width="49"编号/th

th width="90"姓名/th

th width="126"E-mail/th

th width="221"网站/th

th width="80"QQ/th

/tr

%

while(rs.next())

{

%

tr bgcolor="#f8f8f8"

th%= rs.getString(1) %/th

th%= rs.getString(2) %/th

th%= rs.getString(3) %/th

th bgcolor="#f6f6f8"%= rs.getString(4) %/th

th%= rs.getString(5) %/th

/tr

%

}

rs.close();

stmt.close();

con.close();

%

/table

p align="center"br

如果您能看到表格中的数据,说明连接数据库成功!/p

/body

/html

如何用jsp代码把当前页设置为主页

function SetHome(obj,vrl){

try{

obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);

}

catch(e){

if(window.netscape) {

try {

netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

}

catch (e)

{

alert("抱歉!您的浏览器不支持直接设为首页。请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为“true”,点击“加入收藏”后忽略安全提示,即可设置成功。");

}

var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);

prefs.setCharPref('browser.startup.homepage',vrl);

}

}

}

我的网站上就是用的这个函数

在想设置的地方进行如下方式调用:

a onclick="SetHome(this,'');return false;" href="javascript:void(0);"将红柱设为主页/a

JSP网页中使用框架,通过response.setHeader("Refresh","5;URL=index.jsp")返回主页

是frame组合成的吧。

首先要弄清楚JavaSscript 的window中有两个元素:

window.top 指向最顶层的先辈窗口

window.self 指向当前窗口

在使用frame框架时,如:

html

frameset rows="150,*" framespacing="0" border="0" frameborder="0"

frame name="left" src="menu.jsp" scrolling="yes"

frame name="right" src="main.jsp" scrolling="yes"

/frameset

/html

frame(name="right")就假设为你所说的右边的框架为window.self,window.top 即html所标识的窗口。

因此如果在退出的时候要把整个框架退出,为不仅仅右边的退出,那么在退出的页面,也就是index.jsp中添加如下代码,

window.onload=new function ()

{

if (window.top != self)

window.top.location.href='index.jsp';

}

意思就是当主页不是最顶层的窗框时,最顶层的窗口就跳转到主页。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。