(7) Hadoop-based Simple network disk application implementation 3

Source: Internet
Author: User

First, the login.jsp landing interface to extract the Bootmetro-master.zip, and then copy the assets directory under \bootmetro-master\src\ to project.
Bootmetro:https://github.com/aozora/bootmetro, instruction for use: http://www.guoxiaoming.com/bootmetro/


Create a head.jsp file. Used to put some medicine fixed reference CSS, JS file here. As a public calling file.

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

To create a login.jsp file:

 <%@ include file= "head.jsp"%> <%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%> <body style=" text-align:center;margin-bottom:100px; " > <div class= "navbar" > <div class= "Navbar-inner" > <a class= "brand" href= "#" style= "Margin-lef t:200px; " > Network disc </a> </div> </div> <div style= "text-align:left;margin:0px auto;margin-top:50px; width:1200px;height:500px; " > <div style= "float:left;width:800px; Height:100%;background: #009900 "></div> <div style=" float:left;width:400px; height:100%; Background: #00CC33 "> <fieldset> <form action=" Loginservlet "method=" post "class=" Form-horizontal "style= "margin-top:150px;margin-left:100px;"            > User   <input type= "text" id= "Inputemail" name= "username" > <br><br> Password   <input type= "password" id= "Inputpassword" name= "password" > &LT;BR&GT;&LT;BR&GT <button type= "Submit" class= "BTN" > Login </button>     <button type= "Submit" Clas s= "BTN" > Register </button> </form> </fieldset> </div> </div> </bo  Dy>
Start Tomcatserver test effect, want a lot of other gorgeous sister-in-love. We can do it by ourselves. (login is not possible here)


Second, connect the database

(1) Copy the Mysql-connector-java-commercial-5.1.25.jar to the/web-inf/lib folder.


(2) Create user table and add data

Open the navicat for MySQL software. Connect to the Hadoop database and create a user table, then add 3 data to the table.




Iii. creating the model file for the operational database

(1) Conndb.java

Package Com.model;import Java.sql.connection;import Java.sql.drivermanager;public class Conndb {private Connection ct = Null;public Connection Getconn () {try {//Load drive Class.forName ("Com.mysql.jdbc.Driver");//Get Connected ct = Drivermanager.getconnection ("jdbc:mysql://localhost:3306/hadoop?user=root&password=");} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();} return CT;}}


(2) Userbean.java

Package Com.model;public class UserBean {String id; String username; String email; String Password;public string GetId () {return ID;} public void SetId (String id) {this.id = ID;} Public String GetUserName () {return username;} public void Setusername (String username) {this.username = username;} Public String Getemail () {return email;} public void Setemail (String email) {this.email = email;} Public String GetPassword () {return password;} public void SetPassword (String password) {this.password = password;}}

(3) Userbeancl.java

package Com.model;import Java.sql.connection;import Java.sql.resultset;import Java.sql.sqlexception;import Java.sql.Statement; public class Userbeancl {private Statement sm = null;private Connection ct = null;private ResultSet rs = null;public void Close () {try {if (SM! = null) {sm.close (); sm = null;} if (ct! = null) {ct.close (); ct = null;} if (rs! = null) {Rs.close (); rs = null;}} catch (SQLException e) {//TODO auto-generated catch Blocke.printstacktrace ();}} Check whether the logged on user is legitimate public boolean checkUser (string user, String password) {Boolean b = false;try {//Get connected ct = new conndb (). Getconn ( );//Create STATEMENTSM = Ct.createstatement (); rs = Sm.executequery ("SELECT * from user where username=\" "+user+" \ ""); if ( Rs.next ()) {//description user exists string pwd = rs.getstring (3); if (Password.equals (pwd)) {//description password correct b = true;} Else{b = false;}} Else{b = false;}} catch (SQLException e) {e.printstacktrace ();} Finally{this.close ();} return b;}} 

(3) Create Loginservlet file to handle logged-in users

Package Com.controller;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 Org.apache.hadoop.fs.filestatus;import Org.apache.hadoop.mapred.jobconf;import com.model.*;/** * Servlet Implementation class Listservlet */public class Loginservlet extends HttpServlet {/** * @see httpservlet#doget (HttpServle Trequest request, httpservletresponse response) */protected void doget (HttpServletRequest request, HttpServletResponse Response) throws Servletexception, IOException {this.dopost (request, response);} /** * @see Httpservlet#dopost (httpservletrequest request, httpservletresponse response) */protected void DoPost ( HttpServletRequest request, HttpServletResponse response) throws Servletexception, IOException {String username = Request.getparameter ("username"); String Password = request.getparameter ("password"); UsErbeancl UBC = new Userbeancl (); if (Ubc.checkuser (username, password)) {//user is legal. Jump to interface HttpSession session = Request.getsession (); Session.setattribute ("username", username);        jobconf conf = Hdfsdao.config (); Hdfsdao HDFs = new Hdfsdao (conf); filestatus[] List = Hdfs.ls ("/" +username); Request.setattribute ("list", list); Request.getrequestdispatcher (" Index.jsp "). Forward (request, response);} else{//user is not legal. Recall the login interface and prompt for error message request.getrequestdispatcher ("login.jsp"). Forward (request, response); }}


(4) Restart Tomcatserver test, this time will be able to achieve the user landing page jump (from login.jsp jump to index.jsp)




(7) Hadoop-based Simple network disk application implementation 3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.