+ All Categories
Home > Documents > How to create Dynamic Web Application in Java...

How to create Dynamic Web Application in Java...

Date post: 04-Aug-2020
Category:
Upload: others
View: 7 times
Download: 0 times
Share this document with a friend
19
How to create Dynamic Web Application in Java using Eclipse with MS SQL Server Database ? Steps: 1) Download the latest versions of Eclipse and SQL Server (Whatever the latest at your time) Open the eclipse It will ask you to set the workplace path where you want your all the program to be stored in your local machine. In my case I have stored in my D: Drive as shown below. Then Click on Launch. 2) Initially there won’t be package available to create any Web/Enterprise Development (Java EE) Project. You need to install it. For the same go to the Menu Bar > Help > Install New Software. Write down the below link in the search bar and wait till it gets loaded. http://download.eclipse.org/releases/oxygen
Transcript
Page 1: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

How to create Dynamic Web Application in Java using Eclipse with MS

SQL Server Database ?

Steps:

1) Download the latest versions of Eclipse and SQL Server (Whatever the latest at your

time)

Open the eclipse

It will ask you to set the workplace path where you want your all the program to be

stored in your local machine. In my case I have stored in my D: Drive as shown below.

Then Click on Launch.

2) Initially there won’t be package available to create any Web/Enterprise Development

(Java EE) Project. You need to install it. For the same go to the Menu Bar > Help > Install

New Software.

Write down the below link in the search bar and wait till it gets loaded.

http://download.eclipse.org/releases/oxygen

Page 2: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

Click on Web, XML, Java EE and Enterprise Development and then Click > Next.

Page 3: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

Accept the Terms and License agreement and Click on > Finish. Wait for few minutes to

get it done.

3) Now you are done with package installation and ready for creating a New Dynamic Web

Project.

For the same, go to File > New > Project as shown in the picture below.

Page 4: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

You will get the screen shown below.

Page 5: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

Now when you scroll, you get Web folder, expand that folder where you can see

“Dynamic Web Project” as shown below. And Click on > Next.

Now you need to give name of you Web Application which is Project Name, Target

Runtime which is by default Apache Tomcat. Click on > Next.

Page 6: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

Then you will get the screen as below, click again on > Next.

Now, click on “Generate web.xml deployment descripter” and Click > Finish.

Page 7: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

4) Now, right click on the project you created, and go to properties.

Now to Java build Path and Click on Add External Jars.

Page 8: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

Then add only three external Jar files as shown below. Click > Open

Click > Apply and Close.

Page 9: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

5) Now go to the Project explorer and right click on lib and Click > import > Choose “File

System” > Click Next.

Now browse the path where you have stored your three Jar file which we have

imported earlier. Click on > Select Folder.

Page 10: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

Now you will see the screen as shown below and Click on > Finish.

Your lib would be looking as shown below.

You have successfully created Dynamic Web Project in Eclipse with all requirements.

Page 11: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

Creating the JSP page in the Dynamic Web Project:

1) All the Web pages (here JSP) will be made under the “Web Content”. So right click on Web

Content > New > JSP File

Give it a name “index.jsp”, then click > Finish.

Page 12: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

2) Now you need to add following lines into your JSP files.

The core group of tags are the most commonly used JSTL tags. Following is the syntax to include

the JSTL Core library in your JSP –

<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>

The JSTL formatting tags are used to format and display text, the date, the time, and numbers

for internationalized Websites. Following is the syntax to include formatting library in your JSP –

<%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>

Your JSP file will look like this.

As per the requirements you can add remaining lines in the JSP file. Please go through the

following reference material:

https://www.tutorialspoint.com/jsp/jsp_standard_tag_library.htm

Page 13: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

Creating JAVA class and Servlets files

1) All the files with extension .java will be considered as Java Resource and those file need to be

created under the “Java Resources > Src” folder.

Right Click on Src > New > Servlets

Now you need to give name of the Servlet and click on Finish.

Page 14: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

If you click Next, Then you will see the URL Mapping (/EmployeeServlet) which will be used in

the JSP file for action tag in the form submission.

After Clicking on finish, your Java Resources in Project explorer would look like shown below.

Page 15: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

For creating the Class file.

Right click on Src > New > Class.

Give Package name and Class name as shown below. And click on Finish.

Page 16: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

Run the Web Application on Apache Tomcat Server

1) You need to run web application on the apache tomcat server. For that, right click on

WebProject > Run As > Run on Server as shown below.

You need to create new server, Click on the latest version available in your Window. In my case

here it is Apache Tomcat 9.0. I kept the server name as localhost only, but you can change if you

wish. Then click > Next.

Page 17: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

Here you need to select the project which you want to run on the server. In my case it is

MyWebApp. So I moved that project to the right in the given small window. Then click > Finish

You will see console like this. And your webapp would be running in the eclipse only after the

successful Server Startup.

Page 18: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

Code for Database and Application Connectivity.

Connection URL :

jdbc:sqlserver://HOSTNAME\\SQLSERVERNAME;database=DB_Name;user=SQL_User;password=***;

To find HOSTNAME:

1) Widows + R

2) Write “cmd” and click OK

3) Write “hostname” and press ENTER Key.

4) Output is the Hostname of your Laptop/PC

Please go through the below Microsoft Documentation for the reference for Java application and MS

SQL Server Database connectivity.

https://docs.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url?view=sql-server-ver15

Page 19: How to create Dynamic Web Application in Java …eecs.csuohio.edu/~sschung/CIS408/CIS408_SetUpGuide_JAVA...How to create Dynamic Web Application in Java using Eclipse with MS SQL Server

To find SQLSERVERNAME

1) Widows + R

2) Write “ssms” and click OK

3) Click on New Query button.

4) Write query > select @@SERVERNAME

5) See the output in the Results Tab.

a. Output will be with the Hostname which we already found out in the previous step, so

Ignore it)

Reference:

CRUD Example in java: https://www.javatpoint.com/crud-in-servlet

Here don’t forget to change the connection URL in Dao Class. Here they have used Oracle database, in

our case we need to use MS SQL Server Database.


Recommended