Tomcat Java Development (experiment one Java Web Programming brief and JDBC Preliminary)

Source: Internet
Author: User
Tags java web

Today is a year of college entrance examination, in view of our fast test, so the content of the following courses of Java Web Development can only be postponed to write, in order to test, can only summarize the experimental report:

Experiment One:Java Web Programming Brief and JDBC preliminary

Preview report

1 experimental projects: Abrief introduction to Java Web Programming and preliminary JDBC

2

Summary of experimental principles

1 The difference between C/s structure program and b/S structure program

2 The use of common set of methods

3 Working principle of JDBC

4 methods and procedures for JDBC Connection database

5 Methods of using JDBC for CRUD operations

3 Experiment contents and steps:

1 use MySQL to create a database

2 Create a Web project connection database to implement user authentication login Experiment Report:

1

Experimental purposes and requirements

1 Mastering JDBC Technology and working principle

2 Create a Web project connection database to achieve user authentication login 2, experimental environment

Programming Environment: MYSQL,TOMCAT,MYECLIPSE,JDK

Operating system software: Windows XP

3 Experimental content:

1 Create a database and a table to store user names and passwords

2 The development of static Web page file login.htm, for entering user name and password

3) Development of check.jsp files for connection to the database to implement user name password verification

4 Verify successfully into the success.jsp show landing mature, otherwise turn to the failure.jsp show landing failure, again landing. 4 Experimental steps

1 Create a database, Web project.

2 The operation of the project to verify the user login. 5 Experimental results

Fill in your own written check.jsp. The implementation process is as follows:

The first is the login page login.htm

The code is as follows:

<script language= "JavaScript" >
  function Validate (f) {
	  if (!) ( /^\w{5,15}$/.test (F.userid.value))) {
		  alert ("User ID must be 5~15 bit");
		  F.userid.focus ();
		  return false;
     }
	  if (!) ( /^\w{5,15}$/.test (F.password.value))) {
		  alert ("Password must be 5~15 bit");
		  F.password.focus ();
		  return false;
     }
	 return true;
	 }
</script>
<form method= "POST" action= "check.jsp" onsubmit= "return Validate (This)" >
<table >
  <tr>
  <td colspan= "2" > User login program </td>
  </tr>
  <tr>
   <td > Username id:</td>
   <td><input type= "text" name= "userid" ></td>
  </tr>
  <td> password </td>
  <td><input type= "password" name= "password" ></td>
  </tr>
  <tr>
      <td colspan= "2" >
	  <input type= "Submit" value= "Login" >
	  <input type= Reset "value=" "Reset" >
	  </td>
  </tr>
</table>
	
</form>

Login successful success.jsp

The code is as follows:

<%@ page contenttype= "TEXT/HTML;CHARSET=GBK"%>

Login Failed failure.jsp

The code is as follows:

<%@ page contenttype= "TEXT/HTML;CHARSET=GBK"%>

Detection at logon most important: check.jsp this involves connecting to the database

The code is as follows:

<%@ page import= "java.sql.*"%> <%!
	public static final String dbdriver = "Com.mysql.jdbc.Driver";

public static final String Dburl = "jdbc:mysql://localhost:3306/logindemo1?user=root&password=123456";
    %> <% Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;	Boolean flag = false;	Represents a login success or failure Mark%> <% String userid = Request.getparameter ("userid");	Receive form parameter String password = request.getparameter ("password");
		Receive form Parameters try{Class.forName (dbdriver);
		conn = Drivermanager.getconnection (Dburl); String sql = "Select Userid,name from Tuser WHERE userid=?"
		and password=? ";
		pstmt = conn.preparestatement (sql);
		Pstmt.setstring (1,userid);
		Pstmt.setstring (2,password);
		rs = Pstmt.executequery ();
		if (Rs.next ()) {//If there is content, execute here to indicate the query, the legal user flag = true; }}catch (Exception e) {}finally{try{conn.close ();//Connect one off, all operations will close}catch (Exception e) {}}%> <% if ( Flag) {//login successful, should jump to Success.jsp%> <jsp:forward page= "success.jsp"/> <%//Login failed, jump to}else{failure.jsp,%> "Failure.jsp"/> <%}%>

Forgetting is the need to import a jar package that connects to the database.

Put Mysql-connector-java-5.0.8-bin.jar under the Lib folder under the Web-inf folder



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.