jsp页面:
<%@ page contentType="text/html; charset=GBK" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
#Layer1 {
position:absolute;
left:11px;
top:-1px;
width:290px;
height:301px;
z-index:1;
}
body {
background-image: url(images/4.gif);
}
.STYLE4 {
font-size: 20px;
font-weight: bold;
font-family: "宋体";
}
.STYLE5 {font-size: 24px}
-->
</style>
<script language="javascript" type="text/javascript">
function va()
{
document.form1.username.value="";
document.from1.Password.value="";}
</script>
</head><body>
<div id="Layer1">
<form id="form1" name="form1" method="post" action="/BBSWebModule/userservlet">
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3" align="left" valign="top"><img src="images/20051122144654.gif" width="287" height="216" alt=""/></td>
</tr>
<tr>
<td align="right"><span class="STYLE4">用户名</span><strong>:</strong></td>
<td colspan="2" align="left" valign="middle"><input type="text" name="username" /></td>
</tr>
<tr>
<td width="34%" align="right"><span class="STYLE4">密码</span><span class="STYLE5">:</span></td>
<td colspan="2" align="left" valign="middle"><label>
<input type="password" name="Password" />
</label></td>
</tr>
<tr>
<td align="right"><input name="image" type="image"src="images/6.gif" width="60" height="30" alt="" /></td>
<td width="23%"><label><img src="images/2.gif" width="60" height="30" alt="" onclick="return va()"/></label></td>
<td width="43%"><img src="images/151617693.gif" width="90" height="22" alt=""/></td>
</tr>
<tr>
<td colspan="3" align="left"><img src="images/ggb.gif" width="218" height="190" alt=""/></td>
</tr>
</table>
</form>
</div>
</body>
</html>Servlet页面:
package BBSServlet;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import BBSConnection.*;
import java.sql.*;
import BBSBean.*;
import BBSBean.UserBean;
public class UserServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//实例化数据连接对象
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
//Initialize global variables
public void init() throws ServletException {
} //Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
request.setCharacterEncoding("GBK");
response.setCharacterEncoding("GBK");
HttpSession session = request.getSession();
//获取文本框的值
String UserName = request.getParameter("username");
String PassWord = request.getParameter("Password"); String Message = null;
String message = null;
if (UserName.equals("") && PassWord.equals("")) {
Message = "用户名与密码不能为空,请核实后再次登录";
} else if (UserName.equals("")) {
Message = "用户名不能为空,请重新填写";
} else if (PassWord.equals("")) {
Message = "密码不能为空,请重新填写";
} else {
try {
con = DBConnection.getCon();
ps = con.prepareStatement(
"select * from Users where UserName=? and UserPassWord=?");
ps.setString(1, UserName);
ps.setString(2, PassWord);
rs = ps.executeQuery();
if (rs.next()) {
String uname = rs.getString(1);
String upassword = rs.getString(2);
UserBean userbean =new UserBean();
userbean.setUserName(uname);
userbean.setUserPassWord(upassword);
String ub = null;
session.setAttribute("ub", userbean);
request.getRequestDispatcher("topic.jsp").forward(request,
response);
} else {
Message = "您的用户名和密码不存在,请您先注册再登录"; }
session.setAttribute("message", Message);
request.getRequestDispatcher("error.jsp").forward(request,
response);
} catch (Exception e) {
e.printStackTrace();
} finally {
DBConnection.closeResultSet(rs);
DBConnection.closeStatement(ps);
DBConnection.closeConnection(con);
} } } //Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
} //Clean up resources
public void destroy() {
}
}frame框架:<%@page contentType="text/html; charset=GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title>无标题文档</title>
</head>
<frameset rows="100,*" cols="*">
<frame src="top.jsp" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" title="topFrame"/>
<frameset rows="*" cols="311,*">
<frame src="left.jsp" name="leftFrame" scrolling="No" noresize="noresize" id="leftFrame" title="leftFrame"/>
<frame src="main.jsp" name="mainFrame" id="mainFrame" title="mainFrame"/>
</frameset>
</frameset>
<noframes>
<body></body>
</noframes>
</html>
jsp页面提交到Servlet后如何定位到Frame的mainFrame中去
<%@ page contentType="text/html; charset=GBK" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
#Layer1 {
position:absolute;
left:11px;
top:-1px;
width:290px;
height:301px;
z-index:1;
}
body {
background-image: url(images/4.gif);
}
.STYLE4 {
font-size: 20px;
font-weight: bold;
font-family: "宋体";
}
.STYLE5 {font-size: 24px}
-->
</style>
<script language="javascript" type="text/javascript">
function va()
{
document.form1.username.value="";
document.from1.Password.value="";}
</script>
</head><body>
<div id="Layer1">
<form id="form1" name="form1" method="post" action="/BBSWebModule/userservlet">
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3" align="left" valign="top"><img src="images/20051122144654.gif" width="287" height="216" alt=""/></td>
</tr>
<tr>
<td align="right"><span class="STYLE4">用户名</span><strong>:</strong></td>
<td colspan="2" align="left" valign="middle"><input type="text" name="username" /></td>
</tr>
<tr>
<td width="34%" align="right"><span class="STYLE4">密码</span><span class="STYLE5">:</span></td>
<td colspan="2" align="left" valign="middle"><label>
<input type="password" name="Password" />
</label></td>
</tr>
<tr>
<td align="right"><input name="image" type="image"src="images/6.gif" width="60" height="30" alt="" /></td>
<td width="23%"><label><img src="images/2.gif" width="60" height="30" alt="" onclick="return va()"/></label></td>
<td width="43%"><img src="images/151617693.gif" width="90" height="22" alt=""/></td>
</tr>
<tr>
<td colspan="3" align="left"><img src="images/ggb.gif" width="218" height="190" alt=""/></td>
</tr>
</table>
</form>
</div>
</body>
</html>Servlet页面:
package BBSServlet;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import BBSConnection.*;
import java.sql.*;
import BBSBean.*;
import BBSBean.UserBean;
public class UserServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//实例化数据连接对象
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
//Initialize global variables
public void init() throws ServletException {
} //Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
request.setCharacterEncoding("GBK");
response.setCharacterEncoding("GBK");
HttpSession session = request.getSession();
//获取文本框的值
String UserName = request.getParameter("username");
String PassWord = request.getParameter("Password"); String Message = null;
String message = null;
if (UserName.equals("") && PassWord.equals("")) {
Message = "用户名与密码不能为空,请核实后再次登录";
} else if (UserName.equals("")) {
Message = "用户名不能为空,请重新填写";
} else if (PassWord.equals("")) {
Message = "密码不能为空,请重新填写";
} else {
try {
con = DBConnection.getCon();
ps = con.prepareStatement(
"select * from Users where UserName=? and UserPassWord=?");
ps.setString(1, UserName);
ps.setString(2, PassWord);
rs = ps.executeQuery();
if (rs.next()) {
String uname = rs.getString(1);
String upassword = rs.getString(2);
UserBean userbean =new UserBean();
userbean.setUserName(uname);
userbean.setUserPassWord(upassword);
String ub = null;
session.setAttribute("ub", userbean);
request.getRequestDispatcher("topic.jsp").forward(request,
response);
} else {
Message = "您的用户名和密码不存在,请您先注册再登录"; }
session.setAttribute("message", Message);
request.getRequestDispatcher("error.jsp").forward(request,
response);
} catch (Exception e) {
e.printStackTrace();
} finally {
DBConnection.closeResultSet(rs);
DBConnection.closeStatement(ps);
DBConnection.closeConnection(con);
} } } //Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
} //Clean up resources
public void destroy() {
}
}frame框架:<%@page contentType="text/html; charset=GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title>无标题文档</title>
</head>
<frameset rows="100,*" cols="*">
<frame src="top.jsp" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" title="topFrame"/>
<frameset rows="*" cols="311,*">
<frame src="left.jsp" name="leftFrame" scrolling="No" noresize="noresize" id="leftFrame" title="leftFrame"/>
<frame src="main.jsp" name="mainFrame" id="mainFrame" title="mainFrame"/>
</frameset>
</frameset>
<noframes>
<body></body>
</noframes>
</html>
jsp页面提交到Servlet后如何定位到Frame的mainFrame中去
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货