[英]Login and Registration servlets
I'm trying to do servlet with registration I login for the first time. 我正在尝试使用首次登录的注册进行servlet。 So I have problem with log in form. 所以我有登录表单的问题。 Can somebody tell me how to match data from both servlets? 有人可以告诉我如何匹配两个servlet中的数据吗?
I was thinking of something like this if it is possible, so I have tried all that came to my mind. 我一直在想如果可能的话,所以我尝试了所有想到的事情。 I don't know if this is totally wrong. 我不知道这是完全错误的。
if ((super.equals(ul.getEmail())) && (super.equals(ul.getPassword()))) {
or 要么
if(u.getEmail().equals(ul.getEmail()))....{
//( u is User u;)
LOGIN 登录
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
int Id;
String email= request.getParameter("email");
String password= request.getParameter("password");
UserLog ul = new UserLog(email, password);
Session session= HibernateUtil.getSessionFactory().openSession();
Query query = session.createQuery("from UserLog");
List users = query.list();
Transaction t = session.beginTransaction();
Id = (int) session.save(ul);
t.commit();
session.close();
response.sendRedirect("index.jsp");
REGISTRATION 注册
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
int user_id;
String name= request.getParameter("name");
String lname= request.getParameter("lname");
String username= request.getParameter("username");
String email = request.getParameter("email");
String password = request.getParameter("password");
String password2 = request.getParameter("password2");
User u = new User(name, lname, username, email, password, password2);
Session session= HibernateUtil.getSessionFactory().openSession();
Query query = session.createQuery("from User");
List users = query.list();
Transaction t = session.beginTransaction();
user_id = (int) session.save(u);
session.save(u);
t.commit();
session.close();
response.sendRedirect("index.jsp");
Firstly, in Login 首先,登录
Query query = session.createQuery("from UserLog");
is going to return all records from UserLog
. 将要从UserLog
返回所有记录。 Maybe you should use a PreparedStatement
and narrow down your query by using the where
clause. 也许您应该使用PreparedStatement
并通过where
子句来缩小查询范围。
Also, in Login
- why are you creating a Transaction and saving a record? 另外,在“ Login
-为什么要创建事务并保存记录?
Secondly, in Registration
is querying all records again necessary? 其次,在Registration
是否再次查询所有记录是必要的? Maybe if you want to check the existance of a record before adding it? 也许是否要在添加记录之前检查记录的存在? But again use the where
clause. 但是再次使用where
子句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.