如何在jsp页面上实现点击注册按钮,弹出一个窗体来注册(类似于百度贴吧的登录和注册),求详细代码和注释

2024-11-15 16:54:04
推荐回答(3个)
回答1:

jsp中的注册弹出新窗口是通过window.open一个新页面来实现的。
页面register.jsp代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="cn.wy.Pet.User" errorPage="" %>




会员注册例子讲解







用户注册





























用户名:
* 3~16位字母或者数字(如:8hack)
密码:
* 3~16位字母或者数字(如:abc123)
确认密码:
* 必须和上面输入的密码相同
电子邮件:
* 找回密码和联系用(如:8hack@163.com)
联系电话:
如(0871-8888888,13888853113)
联系地址:





后台servlet的处理:
public class reg extends HttpServlet
{
public reg()
{
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out;
DBConnection dbc=null;
String userName;
String psd;
String email;
String tel;
String address;
int popedom;
response.setContentType("text/html;charset=UTF-8");
out = response.getWriter();
try{
dbc = new DBConnection();
PreparedStatement ps = null;
userName = request.getParameter("userName");
psd = login.encrypt(request.getParameter("password1").toString());
email = request.getParameter("email");
tel = request.getParameter("tel");
address = request.getParameter("address");
popedom = Integer.parseInt(request.getParameter("popedom"));
if (userName != null && psd != null && email != null)
{
ps = dbc.getCon().prepareStatement("insert into [User](UName,Upass,UEmail,UTel,UAddress,UPopedom) values(?,?,?,?,?,?)");
ps.setString(1, userName);
ps.setString(2, psd);
ps.setString(3, email);
ps.setString(4, tel);
ps.setString(5, address);
ps.setInt(6, popedom);
ps.execute();
System.out.print("新用户注册:" + request.getParameter("userName") + " ");
out.print("");
}
if (dbc != null)
dbc.dbClose();
}
catch(SQLException ex)
{
out.print("");
ex.printStackTrace();
if (dbc != null)
dbc.dbClose();
}
}
}

回答2:





无标题文档







关 闭






              在这里设置注册按钮






专门帮你做的,记得给分哈。

回答3:

window.open()..........