我有一个jsp的页面(代码如下),老大让我在[color=#0000FF]点击“登录”时弹出个窗口,要输入相同的人员编号及密码后,界面才可以到下一页,哪位大侠帮下忙!!教教我怎么做!![/color]<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"
prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"
prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic"
prefix="logic"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles"
prefix="tiles"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-template"
prefix="template"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-nested"
prefix="nested"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%String webpath = request.getContextPath();
%>
<link rel="stylesheet" type="text/css" media="screen" href="css/qydl.css" />
<HTML>
<HEAD>
<TITLE>用户登录</TITLE>
<style type="text/css">
<!--
.STYLE1 {
font-family: "黑体";
font-size: 36px;
font-weight: bold;
color: #6F067B;
}
.STYLE2 {
font-size: 14px;
font-weight: bold;
color: #6F067B;
}
-->
</style>
<script language="javascript">
function checkform(){
if(document.all.userid.value==''){
alert("人员号不能为空!");
return false;
}
if(document.all.userpwd.value==''){
alert("登录密码不能为空!");
return false;
}
}
</script>
</HEAD>
<body vLink="#000000" aLink="#6f067b" link="#000000" leftMargin="0" topMargin="0"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top">
<table width="100%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td background="img/bg1.gif"> </td>
</tr>
</table>
<table width="100%" height="21" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="right" valign="bottom" background="img/bg1_1.gif"> </td>
</tr>
</table>
<table width="100%" height="50" border="0" cellpadding="0" cellspacing="0" style="border-bottom:#000000 solid 1px;">
<tr>
<td width="30%" bgcolor="#FFFFFF"><img src="img/logo.gif" width="214" height="65" /></td>
<td width="70%" align="right" bgcolor="#FFFFFF"><img src="img/yg.jpg" width="409" height="55" style="margin-right:5px;" /></td>
</tr>
</table>
<table width="100%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#C8B430"> </td>
</tr>
</table>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top:50px;">
<tr>
<td width="600" height="50" align="center"><span class="STYLE1">用户登录</span></td>
</tr>
<tr>
<td width="600" height="250">
<html:form action="loginAction" onsubmit="return checkform();">
<table width="250" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="98" height="40"><span class="STYLE2">人员编号:</span></td>
<td width="150" height="40" colspan="2"><input name="userid" type="text" style="width:152px;border:#000000 solid 1px;"></td>
</tr>
<tr>
<td width="98" height="40"><span class="STYLE2">登录密码:</span></td>
<td width="150" height="40" colspan="2"><input name="userpwd" type="password" style="width:152px;border:#000000 solid 1px;"></td>
</tr>
<tr>
<td width="98" height="40" valign="bottom"> </td>
<td width="76" height="40" align="left" valign="bottom"><input name="submit" type="submit" id="submit" value="登 录" class="button">
</td>
<td width="76" height="40" align="right" valign="bottom"><input name="subcancel" type="reset" id="subcancel" value="重 写" class="button"></td>
</tr>
<tr>
<td height="60" colspan="3">
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b><html:errors property="login.error" /></b></td>
</tr>
</table></td>
</tr>
</table>
</html:form>
</td>
</tr>
</table></td>
</tr>
</table>
</BODY>
</HTML>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"
prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"
prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic"
prefix="logic"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles"
prefix="tiles"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-template"
prefix="template"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-nested"
prefix="nested"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%String webpath = request.getContextPath();
%>
<link rel="stylesheet" type="text/css" media="screen" href="css/qydl.css" />
<HTML>
<HEAD>
<TITLE>用户登录</TITLE>
<style type="text/css">
<!--
.STYLE1 {
font-family: "黑体";
font-size: 36px;
font-weight: bold;
color: #6F067B;
}
.STYLE2 {
font-size: 14px;
font-weight: bold;
color: #6F067B;
}
-->
</style>
<script language="javascript">
function checkform(){
if(document.all.userid.value==''){
alert("人员号不能为空!");
return false;
}
if(document.all.userpwd.value==''){
alert("登录密码不能为空!");
return false;
}
}
</script>
</HEAD>
<body vLink="#000000" aLink="#6f067b" link="#000000" leftMargin="0" topMargin="0"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top">
<table width="100%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td background="img/bg1.gif"> </td>
</tr>
</table>
<table width="100%" height="21" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="right" valign="bottom" background="img/bg1_1.gif"> </td>
</tr>
</table>
<table width="100%" height="50" border="0" cellpadding="0" cellspacing="0" style="border-bottom:#000000 solid 1px;">
<tr>
<td width="30%" bgcolor="#FFFFFF"><img src="img/logo.gif" width="214" height="65" /></td>
<td width="70%" align="right" bgcolor="#FFFFFF"><img src="img/yg.jpg" width="409" height="55" style="margin-right:5px;" /></td>
</tr>
</table>
<table width="100%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#C8B430"> </td>
</tr>
</table>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top:50px;">
<tr>
<td width="600" height="50" align="center"><span class="STYLE1">用户登录</span></td>
</tr>
<tr>
<td width="600" height="250">
<html:form action="loginAction" onsubmit="return checkform();">
<table width="250" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="98" height="40"><span class="STYLE2">人员编号:</span></td>
<td width="150" height="40" colspan="2"><input name="userid" type="text" style="width:152px;border:#000000 solid 1px;"></td>
</tr>
<tr>
<td width="98" height="40"><span class="STYLE2">登录密码:</span></td>
<td width="150" height="40" colspan="2"><input name="userpwd" type="password" style="width:152px;border:#000000 solid 1px;"></td>
</tr>
<tr>
<td width="98" height="40" valign="bottom"> </td>
<td width="76" height="40" align="left" valign="bottom"><input name="submit" type="submit" id="submit" value="登 录" class="button">
</td>
<td width="76" height="40" align="right" valign="bottom"><input name="subcancel" type="reset" id="subcancel" value="重 写" class="button"></td>
</tr>
<tr>
<td height="60" colspan="3">
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b><html:errors property="login.error" /></b></td>
</tr>
</table></td>
</tr>
</table>
</html:form>
</td>
</tr>
</table></td>
</tr>
</table>
</BODY>
</HTML>
解决方案 »
- TOMCAT启动时提示IP_ADD_MEMBERSHIP failed错误
- 一个下载的问题
- 在页面布局上,现在是tiles 框架用的多,还是frameset用的多?
- 在weblogic portal中,将一个现成的portlet(.war文件)集成进来的问题
- MyEclipse中访问MySQL数据库,出现乱码如何解决
- 请教:jsp里是用java还是用javascript啊?多谢
- 大型网站搭建...架构设计前的准备工作.
- 高手请进,好奇怪的问题
- 在struts的Action中使用response.sendRedirect出现错误(在Tomcat 4.1.24)
- tomcat的初始内存和最大内存分别设置为多少合适
- java如何在DOS中实现UNIX的登陆
- 除JFreeChart还有别的工具可以生成图表吗?
1.〈SCRIPT LANGUAGE="javascript"〉
〈!--
window.open (´page.html´)
--〉
〈/SCRIPT〉
window.open (´page.html´) 用于控制弹出新的窗口page.html,如果page.html不与主窗口在同一路径下,前面应写明路径,绝对路径(http://)和相对路径(../)均可。
用单引号和双引号都可以,只是不要混用。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<STYLE>
#login{
position: relative;
display: none;
top: 20px;
left: 30px;
background-color: #ffffff;
text-align: center;
border: solid 1px;
padding: 10px;
z-index: 1;
}
</STYLE>
<script type="text/javascript">
var W = screen.width;//取得屏幕分辨率宽度
var H = screen.height;//取得屏幕分辨率高度function M(id){
return document.getElementById(id);//用M()方法代替document.getElementById(id)
}
function MC(t){
return document.createElement(t);//用MC()方法代替document.createElement(t)
};
//判断浏览器是否为IE
function isIE(){
return (document.all && window.ActiveXObject && !window.opera) ? true : false;
}
//取得页面的高宽
function getBodySize(){
var bodySize = [];
with(document.documentElement) {
bodySize[0] = (scrollWidth>clientWidth)?scrollWidth:clientWidth;//如果滚动条的宽度大于页面的宽度,取得滚动条的宽度,否则取页面宽度
bodySize[1] = (scrollHeight>clientHeight)?scrollHeight:clientHeight;//如果滚动条的高度大于页面的高度,取得滚动条的高度,否则取高度
}
return bodySize;
}
//创建遮盖层
function popCoverDiv(){
if (M("cover_div")) {
//如果存在遮盖层,则让其显示
M("cover_div").style.display = 'block';
} else {
//否则创建遮盖层
var coverDiv = MC('div');
document.body.appendChild(coverDiv);
coverDiv.id = 'cover_div';
with(coverDiv.style) {
position = 'absolute';
background = '#CCCCCC';
left = '0px';
top = '0px';
var bodySize = getBodySize();
width = bodySize[0] + 'px'
height = bodySize[1] + 'px';
zIndex = 0;
if (isIE()) {
filter = "Alpha(Opacity=60)";//IE逆境
} else {
opacity = 0.6;
}
}
}
}
//让登陆层显示为块
function showLogin()
{
var login=M("login");
login.style.display = "block";
}//设置DIV层的样式
function change(){
var login = M("login");
login.style.position = "absolute";
login.style.border = "1px solid #CCCCCC";
login.style.background ="#F6F6F6";
var i=0;
var bodySize = getBodySize();
login.style.left = (bodySize[0]-i*i*4)/2+"px";
login.style.top = (bodySize[1]/2-100-i*i)+"px";
login.style.width = i*i*4 + "px";
login.style.height = i*i*1.5 + "px";
popChange(i);
}
//让DIV层大小循环增大
function popChange(i){
var login = M("login");
var bodySize = getBodySize();
login.style.left = (bodySize[0]-i*i*4)/2+"px";
login.style.top = (bodySize[1]/2-100-i*i)+"px";
login.style.width = i*i*4 + "px";
login.style.height = i*i*1.5+ "px";
if(i<=10){
i++;
setTimeout("popChange("+i+")",10);//设置超时10毫秒
}
}
//打开DIV层
function open()
{
change();
showLogin();
popCoverDiv()
void(0);//不进行任何操作,如:<a href="#">aaa</a>
}
//关闭DIV层
function close(){
M('login').style.display = 'none';
M("cover_div").style.display = 'none';
void(0);
}</script>
</head><body><a href="javascript:open();">登陆</a><div id="login">
<span>用户登陆</span>
<div id="panel">
<lable>用户名: </lable><input type="text" size="20" />
<lable>密码: </lable><input type="password" size="20">
<input type="checkbox" /><lable>登陆</lable>
</div>
<input type="button" value="提交" />
<a href="javascript:close();">关闭</a>
</div>
</body>
</html>
如果是這樣的需求:
我給出的做法是:
1.增加一個對話頁面框,叫login.jsp吧!然後返回一個數組(123123@123123)
2.在JS,增加這段代碼doLoginCheck(obj);
3.<script language="javascript">
function checkform(){
if(document.all.userid.value==''){
alert("人员号不能为空!");
return false;
}
if(document.all.userpwd.value==''){
alert("登录密码不能为空!");
return false;
}
doLoginCheck(obj);
}
function doLoginCheck(obj) {
var returnValue = window.showModalDialog('../login.jsp',window,"status:false;dialogWidth:400px;dialogHeight:280px");
if(returnValue != null) {
var array = returnValue.split("@");
var userID = array[0];
var userPassword = array[1]; if(document.all.userid.value == userID && document.all.userpwd.value==userPassword ) {
//進行下一步操作
} else {
//給相應的提示
}
}
}
</script>
JS实现。欢迎加入JAVA交流群72923840
window.open(pageURL,name,parameters)
其中:
pageURL 为子窗口路径
name 为子窗口句柄
parameters 为窗口参数(各参数用逗号分隔) 二、各项参数
其中yes/no也可使用1/0;pixel value为具体的数值,单位象素。 参数 | 取值范围 | 说明 alwaysLowered | yes/no | 指定窗口隐藏在所有窗口之后
alwaysRaised | yes/no | 指定窗口悬浮在所有窗口之上
depended | yes/no | 是否和父窗口同时关闭
directories | yes/no | Nav2和3的目录栏是否可见
height | pixel value | 窗口高度
hotkeys | yes/no | 在没菜单栏的窗口中设安全退出热键
innerHeight | pixel value | 窗口中文档的像素高度
innerWidth | pixel value | 窗口中文档的像素宽度
location | yes/no | 位置栏是否可见
menubar | yes/no | 菜单栏是否可见
outerHeight | pixel value | 设定窗口(包括装饰边框)的像素高度
outerWidth | pixel value | 设定窗口(包括装饰边框)的像素宽度
resizable | yes/no | 窗口大小是否可调整
screenX | pixel value | 窗口距屏幕左边界的像素长度
screenY | pixel value | 窗口距屏幕上边界的像素长度
scrollbars | yes/no | 窗口是否可有滚动栏
titlebar | yes/no | 窗口题目栏是否可见
toolbar | yes/no | 窗口工具栏是否可见
Width | pixel value | 窗口的像素宽度
z-look | yes/no | 窗口被激活后是否浮在其它窗口之上 三、用函数控制弹出窗口下面是一个完整的代码。 <html>
<head>
<script LANGUAGE="JavaScript">
<!--
function openwin() { window.open ("page.html", "newwindow", "height=100, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no")
//写成一行
}
//-->
</script>
</head>
<body onload="openwin()">
…任意的页面内容…
</body>
</html>
这里定义了一个函数openwin(),函数内容就是打开一个窗口。在调用它之前没有任何用途。
怎么调用呢?
方法一:<body onload="openwin()"> 浏览器读页面时弹出窗口;
方法二:<body onunload="openwin()"> 浏览器离开页面时弹出窗口;
方法三:用一个连接调用:
<a href="#" onclick="openwin()">打开一个窗口</a>
注意:使用的"#"是虚连接。
方法四:用一个按钮调用:
<input type="button" onclick="openwin()" value="打开窗口">
你这里是在登陆的时候弹出一个新窗口,用的是按钮调用.四、在弹出窗口中加上一个关闭按钮
<FORM>
<INPUT TYPE='BUTTON' VALUE='关闭' onClick='window.close()'>
</FORM>
function openWindow(yourURL){
mm=window.showModalDialog(yourURL,arguments,'dialogHeight:270px;dialogWidth:400px;status:no;toolbar:no;resizable:no;menubar:no;location:no;scrollbars:no;dialogLeft:'+(screen.width/2.0-150)+',dialogTop:170')
if(mm!=null){
doTrClick();
t1.value=mm;
}
}