English 中文(简体)
谷歌应用者登记系统
原标题:Google App Engine User Registration System

我正在 go角设计一个用户登记制度,迄今为止,我可以开发该仪器的登记方。 但是,我可以 log立,制造一种HttpSession。

在此,我设立了日志和两个文本箱,以输入电子邮件和密码。

And then I created Bean class and DAO class as following. package com.myfirstguide.beans;

import javax.servlet.http.HttpSession;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.PreparedQuery;
import com.google.appengine.api.datastore.Query;

public class UserDAO {

public static UserBean login(UserBean bean){

    String email = bean.getEmail();
    String password = bean.getPassword();

    try{
        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        Query q = new Query("Account");
        q.addFilter("email", Query.FilterOperator.EQUAL, email);
        q.addFilter("password", Query.FilterOperator.EQUAL, password);

        PreparedQuery pq = datastore.prepare(q);
        Entity result = pq.asSingleEntity();
        if(result != null){
            bean.setValid(true);

        }

        //return bean;
    }catch(Exception e){

    }
    return bean;
}

}

这里是英国人。

package com.myfirstguide.beans;

public class UserBean {

private String username; 
private String password; 
private String firstName;
private String lastName; 
private String email;
public boolean valid; 

public String getFirstName() {
    return firstName; 
} 

public void setFirstName(String newFirstName) { 
    firstName = newFirstName; 
} 

public void setEmail(String semail){
    email = semail;
}

public String getEmail(){
    return email;
}

public String getLastName() {
    return lastName; 
} 

public void setLastName(String newLastName) { 
    lastName = newLastName; 
} 

public String getPassword() { 
    return password;
} 

public void setPassword(String newPassword) { 
    password = newPassword;
} 

public String getUsername() {
    return username; 
} 

public void setUserName(String newUsername) {
    username = newUsername; 
} 

public boolean isValid() {
    return valid;
} 

public void setValid(boolean newValid) {
    valid = newValid;
} 
 }

这里是Serlet。

package com.myfirstguide.users;

import java.io.IOException;

import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.myfirstguide.beans.UserBean;
import com.myfirstguide.beans.UserDAO;

 public class SignIn extends HttpServlet{

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    String email = req.getParameter("email");
    String password = req.getParameter("password");

    try{
        UserBean ubean = new UserBean();
        ubean.setEmail(email);
        ubean.setPassword(password);

        ubean = UserDAO.login(ubean);
        if(ubean.isValid()){
              HttpSession session = req.getSession(true);       
              session.setAttribute("currentSessionUser",ubean); 
              resp.sendRedirect("index.jsp?session=" + ubean.getFirstName()); //logged-in page      
        }
    }catch(Throwable e){
        System.out.println(e);
    }

}

 }

我不知道人民军。 如果能更好地做到这一点,请告诉我。

谢谢!

问题回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签