The general requirement is to do a desk lamp project, three professions each have division of labor, we are sent to do an online shopping website. The group of three students in this major, are sister ... To see this situation my intuition is "bad, to do backstage development" ... The hunch is right, that's what it looks like.
July 7, 82 days, the teacher told a simple javaweb example: User login. There are username and password in the database, the match is successful before you can log in, jump to the Welcome screen, display the user name.
The schema is as follows:
|-jspservlet
|-src
|-jspservlet.dao//Storage Interface
Userdao.java
|-jspservlet.dao.impl//the implementation class of the storage interface
Userdaoimpl.java
|-jspservlet.db//Database Connection Operations
Dbconnect.java
|-jspservlet.servlet//used to connect the front and back, don't know what to call
Loginservlet.java
|-jspservlet.vo//user attributes, Getter Setters, feel like JavaBean.
User.java
|-webroot
|-web-inf
Xml
login.jsp
error.jsp
welcome.jsp
Login easier to get started, the teacher made a new request yesterday: registration.
Because the registration also uses the properties in the user class, I haven't changed it. Userdao is the interface, but also has not changed, but adds a new implementation class Userdaoimpreg, joins the section to add new class Registerservlet.
PackageJspservlet.dao.impl;Importjava.sql.PreparedStatement;ImportJava.sql.ResultSet;Importjava.sql.SQLException;ImportJspservlet.dao.UserDAO;ImportJspservlet.db.DBConnect;ImportJspservlet.vo.User; Public classUserdaoimpregImplementsuserdao{ Public intQuerybyusername (user user)throwsException {intFlag = 1; String SQL= "SELECT * from UserInfo where username=?"; String Sqladd= "INSERT into Javawebdb.userinfo values (?,?)"; PreparedStatement pstmt=NULL; Dbconnect DBC=NULL; //Database Connection Try{DBC=NewDbconnect (); Pstmt=dbc.getconnection (). preparestatement (SQL); Pstmt.setstring (1, User.getusername ()); //Query the tuple that corresponds to the input informationResultSet rs =Pstmt.executequery (); //Verify that there is a conflict with a user name already in the database if(Rs.next ()) {if(Rs.getstring ("username"). Equals (User.getusername ())) {flag= 0; } } if(Flag = = 1){ //writes new user information to the database if it does not conflictPSTMT =dbc.getconnection (). Preparestatement (Sqladd); Pstmt.setstring (1, User.getusername ()); Pstmt.setstring (2, User.getpassword ()); Pstmt.executeupdate (); } rs.close (); Pstmt.close (); } Catch(SQLException e) {System.out.println (E.getmessage ()); } finally { //To close a database connectionDbc.close (); } returnFlag; }}
Had not been added executeupdate (), the information is not written in, later found that the problem is here.
The afternoon toss toss a product database, ready to do query function.
Alas, the main is the previous only to learn Java, have not contacted Javaweb, so get started somewhat slow. But the beginning of everything is difficult, tomorrow is expected to be much smoother.
Backend Development Log (a): User registration