TOMCAT8 Java8 Eclipse4.4 servlet Development environment Construction

Source: Internet
Author: User
Tags sqlite apache tomcat

Tomcat8 Java8 Eclipse4.4 servlet development Environment Construction

■ Overview

Os:microsoft Windows [Version 6.0.6002]

Eclipse. 4.4:version:luna Service Release 2 (4.4.2) Build id:20150219-0600

http://www.eclipse.org/

Java:java version "1.8.0_20" Java (TM) SE Runtime Environment (build 1.8.0_20-b26)

Http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html#javasejdk

Tomcat:server version:apache tomcat/8.0.21 Server Built:mar 14:11:21 UTC

http://tomcat.apache.org/download-80.cgi

■ Configuration

New->server->tomcat v8.0 Server

localhost

ServerName

Apache Tomcat v8.0

Resource

Coding UTF-8

File->new->other

Web->servlet

Create Servelt

Example

Package example.part1;

Import java.io.IOException;

Import javax.servlet.ServletException;

Import Javax.servlet.annotation.WebServlet;

Import Javax.servlet.http.HttpServlet;

Import Javax.servlet.http.HttpServletRequest;

Import Javax.servlet.http.HttpServletResponse;

/**

* Servlet Implementation Class HelloWorld

*/

@WebServlet ("/helloworld")

public class HelloWorld extends HttpServlet {

Private static final long serialversionuid = 1L;

/**

* @see Httpservlet#httpservlet ()

*/

Public HelloWorld () {

Super ();

TODO auto-generated Constructor stub

}

/**

* @see Httpservlet#doget (httpservletrequest request, httpservletresponse response)

*/

protected void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {

TODO auto-generated Method Stub

Response.getwriter (). Write ("Hello, world!");

}

/**

* @see Httpservlet#dopost (httpservletrequest request, httpservletresponse response)

*/

protected void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {

TODO auto-generated Method Stub

}

}

New->other

web->jsp File

Example omitted

■ Sqlite

http://www.sqlite.org/

SQLite 3.8.9

Jdbc

Https://bitbucket.org/xerial/sqlite-jdbc/downloads

Sqlite3.exe Testdb.sqlite

CREATE TABLE UserInfo (

UserID VARCHAR (PRIMARY KEY),

Status INTEGER not NULL

);

INSERT into UserInfo (userid, status) VALUES ("aaaa1234", 0);

INSERT into UserInfo (userid, status) VALUES ("zzzz9876", 2);

SELECT * from UserInfo;

Connection conn = null;

Statement stmt = null;

ResultSet rs = null;

try {

Class.forName ("Org.sqlite.JDBC");

conn = Drivermanager.getconnection ("Jdbc:sqlite:c:/sqlite/testdb.sqlite");

stmt = Conn.createstatement ();

rs = Stmt.executequery ("Select Userid,status from UserInfo");

Resp.setcontenttype ("Text/plain");

while (Rs.next ()) {

Resp.getwriter (). Write ("userid=" + rs.getstring ("userid") + ",");

Resp.getwriter (). Write ("status=" + rs.getstring ("status") + "\ n");

}

} catch (Exception e) {

E.printstacktrace ();

} finally {

if (rs! = null) {try {rs.close ();} catch (SQLException e) {e.printstacktrace ()}}

if (stmt! = null) {try {stmt.close ();} catch (SQLException e) {e.printstacktrace ()}}

IF (conn! = null) {try {conn.close ();} catch (SQLException e) {e.printstacktrace ()}}

}

■ Mysql

CREATE TABLE UserInfo (

UserID VARCHAR (PRIMARY KEY),

Status INTEGER not NULL

)

Engine=innodb

;

INSERT into UserInfo (userid, status) VALUES ("aaaa1234", 0);

INSERT into UserInfo (userid, status) VALUES ("zzzz9876", 2);

Connection conn = null;

Statement stmt = null;

ResultSet rs = null;

try {

Class.forName ("Com.mysql.jdbc.Driver"). newinstance ();

conn = Drivermanager.getconnection ("jdbc:mysql://192.168.11.187/sampledb?user=username&password=xxxxx");

stmt = Conn.createstatement ();

rs = Stmt.executequery ("Select Userid,status from UserInfo");

Response.setcontenttype ("Text/plain");

while (Rs.next ()) {

Response.getwriter (). Write ("userid=" + rs.getstring ("userid") + ",");

Response.getwriter (). Write ("status=" + rs.getstring ("status") + "\ n");

}

} catch (Exception e) {

E.printstacktrace ();

} finally {

if (rs! = null) {try {rs.close ();} catch (SQLException e) {e.printstacktrace ()}}

if (stmt! = null) {try {stmt.close ();} catch (SQLException e) {e.printstacktrace ()}}

IF (conn! = null) {try {conn.close ();} catch (SQLException e) {e.printstacktrace ()}}

}

Finish


TOMCAT8 Java8 Eclipse4.4 servlet Development environment Construction

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.