Before pitching into the JSP and Servlet tutorial, we will see how to install the software needed for Java web programming. You can skip JSP and Servlet tutorial, if you have following software(s) installed in your machine already.
- Eclipse - Integrated Development and Environment
- Apache Tomcat - Application server
- MySQL server - Database server
Eclipse - Integrated Development Environment(IDE) Installation:
- Step 1: Goto Eclipse website and download Indigo package as shown below:
- Step 2: After the window 32 or 64 bit link is clicked, it will take you to download page where you need to select mirror server[download server] as shown below:
- Step 3: Unzip the downloaded content and clcik on eclipse exe to launch the IDE:
- Step 4: You could see the welcome page upon clicking the eclipse.exe as shown below. Select workbench out of it to launch Java or Web project editor.
- Step 5: Eclipse has been successfully installed. You could create a sample java program as shown below:
import java.io.*; class MyFirstClass{ public static void main(String args[]){ System.out.println("Helllo World"); } }
Goto File>>New>>Other>>Java>>Java Project to create a new Java Project
Create Java class under src folder of the newly created project
Have a look at below image!
Apache tomcat server Installation:
- Step 1: Goto Apache website and download Apache server as shown below:
Step 2: Unzip the downloaded content into a folder called apache-tomcat-[version].
- Step 3: Make sure to set JAVA_HOME or JRE_HOME in your system environmental variable since Java is needed to run Apache server. Here is the few steps to check if java is installed in your machine.
- Type java -version in command prompt, you could see java version installed in your system.
- If you get "Java is not recognized as an internal or external command.....", make sure to install Java.
- Click here to install java+ set JDK or JRE path.
- Step 4: Double click on startup.bat file located right under apache-tomcat-[version]\bin. You could see one window as shown below. Make sure that the server has been started by looking at the "LAST LINE" of the server console.
- Step 5: After startup, the default web applications included with Tomcat will be available by visiting:
- TroubleShoot: If startup.bat doesn't work, make sure the JAVA_HOME is set properly.
MySQL - Database server Installation:
- Step 1: Goto MySQL website and download MySQL Workbench(GUI) . [Note: Windows (x86, 32-bit), MSI Installer]
- Step 2: Select download server which is nearest to your locality. [Note: Select "No thanks, just take me to the downloads!" link in order to choose the mirror server]
- Step 3: Run the downloaded exe file and make sure you download the prerequisites software.[Note: If your system doesn't have necessary software to run sql workbench, installer will recommend you to install the same]. MySQL workbench will be launched once it is installed successfully.
package com.mysql.examples; import java.sql.*; public class Example1 { static Connection conn=null; static Statement stmt=null; static ResultSet rs=null; static int i; public static void main(String args[]){ try{ Class.forName("com.mysql.jdbc.Driver").newInstance(); conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/logindatabase?"+ "user=root&password=password"); System.out.println(conn); stmt=conn.createStatement(); i=stmt.executeUpdate("insert into userlogin values('vind','vind',123)"); rs=stmt.executeQuery("select user from userlogin"); while(rs.next()){ System.out.println(rs.getString(1)); } } catch(Exception ce){ System.out.println("No driver found"); System.out.println(ce.getMessage()); } } }
0 comments: