Web Development Using Java Technology For Beginners
Last Updated :
24 May, 2022
In order to create a java web-based project with which the knowledge is up to programming language then you can follow the simple flow explained below while creating a project being a beginner. The first step geek in order to create such web development projects requires the knowledge about the web technologies carried forward to other frameworks. There are many ways to create such Java web projects, where there are many frameworks spring, maven, hibernate, etc depending on the requirement of the project. For a naive user knowledge will be missing out for Collection, framework, and web technologies but still, if someone wants to develop a proper java web application, the least idea of how to proceed further will require at least a combination of technologies to use with clear concepts of programming in any language preferably be it java or python as these days most of the tools are developed using these languages. So in order to combat these languages are preferred these days.
Here is an approach or technology as a combination of technologies that one can follow for a simple web application who is having a basic knowledge of core java and a bit of knowledge of advanced java working with the database. In order to create a project one must be clear about the two ends, this includes frontend and backend.
- Frontend refers to the part built from where the user can access the application. In a web application, web pages act as a user. And in the said approach you will use JSP and HTML pages.
- Backend refers to the pages that are being accessed by the user that will be handled and controlled through the backend process that needs to be developed. It is also known as “server-side” where the data records, data management, and logic controls are done.
Real-life Situation
Consider an architecture of a mall in which people working on building it by piling on bricks as cells as per the instructions received to them. These set of people are called frontend builders while the sets of people working over laying layout on a piece of paper later on dealing with science in order to give maximum stability to the foundation which is to be laid further involving research and development over it are called backend people. These people have sent instruction to frontend people after doing research, development and testing.
Now coming back to the project, for the frontend or UI(User Interface) one can either opt for swing or JSP. Here taking JSP for the illustration part out of swing and JSP which stands for Java Server Pages
JSP stands for Java Server Pages. If you know HTML, CSS you are less far to Know JSP(a java server page), where you use HTML tags only with extra features for which JSP acts as a dynamic web page. You can use HTML pages as well instead of JSP if you want to start with a simpler approach.
The input from users can be collected through the forms of a webpage by using JSP and the records from the database system are able to appear in the form of view respectively. In order to retrieve the information containing data from the database system, the available tags of JSP are used and these tags are used for different related functionalities like going from one page to another and similarly for other means as well
Implementation: Suppose you have a webpage like a form field, the data entered in the field(by the user) will be accessed by java programming with the help of Servlet.
Example: JSP pages are helpful to retrieve the information from the database and show it on the web pages to users.
login.jsp
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>login here</title>
</head>
<body>
<form action="userlogin" method="post">
User Name <input type="text" name="username"><br>
Password <input type="password" name="password"><br>
<input type="submit" value="login">
</form>
</body>
</html>
In the above example below tag is the action that defines the servlet it will direct to after the button is submitted. Servlet example on login will be seen in the latter half.
Tag:
<form action="userlogin" method="post"> tag -> action
Back-End: It does involve a programming language where here java is taken for the illustration part.
As you are making a project on java you should have knowledge of java definitely to work on the logic like accessing the data from the database and working on it then sent back to the server in the UI part etc, this is the main backend section where the logical part will be implemented.
Java will act as a medium that will connect UI(need to know about Servlet) and database(need to know about JDBC) with its logic. One has to install IDE for java such as Eclipse or Netbeans, etc.
Note: Eclipse is more preferable if using jsp instead of swing if used in frontend
Servlets are the Java programs that run on the Java-enabled web server or application server. They are used to handle the request obtained from the webserver, process the request, produce the response, then send the response back to the webserver. Though it is a java class, required in a web project. Suppose you have a webpage like form fields, the data entered in the field will be accessed by java programming with the help of Servlet. Servlet helps to redirect from web pages to servlet and these servlet classes will help to connect with other java classes.
There are some common functions you'll require using in servlet:
Implementation: HttpServlet class is used here
Example: It is provided on the basis of JSP page example as shown above
// Importing required basic classes
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
// Importing classes from java.servlet package
// for connectivity of application class
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
// Since userlogin is used in action="userlogin"
// form tag in jsp page
@WebServlet("/userlogin")
// Class 1
// Helper class extending HttpServlet main class
public class LoginServlet extends HttpServlet
{
// Method
@Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// Customly setting name and password
String name = request.getParameter("name");
String password = request.getParameter("password");
....
// Further programming
// Code can be appended here onward so
}
}
Database: Most web apps require a place to store data for which database is used,e.g., suppose there is a webpage registering as a new user. Now think, where all these data will be saved? Here we can use a database that will store the data of the user, which will be accessible all the time. However, these data will be accessed with the help of backend code written in java and will be connecting with UI as well as explained in the java section as well.
As a beginner you should use a relational database, you can install:
JDBC: If you are using java and a database like MySQL.How will you communicate with it as you cannot use SQL commands directly? For that, you will have to use JDBC(java database connectivity) that will connect the database and there are some abstract classes like Connection, etc will have to use.
With that, you will have to add a jar file
For MySQL DB->mysql connector jar file and for
For Oracle->ojdbc jar file
Implementation: Both connection class and application(Main) class is represented in a single frame as follows where the first frame is the connection class for the JDBC which returns out the connection class object. The second frame represents the application class of the corresponding connection class.
Example
Java
// Java Program to Illustrate JDBC Connection In Oracle DB
// Importing database
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import oracle.jdbc.driver.OracleDriver;
// Class 1
// JDBC Connection Class
// To communicate with the database
// Note: This class is to be used in Application class
// where moto of this class is connection object
public class JDBCconnection {
// Declaring connection class object and
// initializing it to null
private static Connection connection = null;
// Method
// Static method that connects with database
public static Connection getConnection()
{
// Try block to check for exceptions
try {
// Loading and registering drivers
// using DriverManager
// Setting instance as Oracle driver
// This implies database is Oracle
DriverManager.registerDriver(
new OracleDriver());
// Passing DB- URL,username,password
connection = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe",
"username", "password");
}
// Catch block ot handle DB exception
catch (SQLException e) {
// Display the line number where exception
// occurred using printStackTrace() method
e.printStackTrace();
}
// If no exception caught database is connected
return connection;
// Display message successful connection
System.out.print("Connection established");
}
}
Java
// Java Program to Illustrate JDBC Connection In SQL DB
// Importing database
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
// Main class
// Application class
public class JdbcMySql {
// Main driver method
public static void main(String[] args)
{
// Try block to check for exceptions
try {
// Setting database type for connection as MYSQL
Class.forName("com.mysql.jdbc.Driver");
// Loading and registering driver
// MYSQL database iul with DB
// name, username and password
Connection connection
= DriverManager.getConnection(
"jdbc:mysql://localhost:3306/databaseName",
"username", "password");
// If connection done with database this
// statements will be printed otherwise exception
// will be caught
System.out.println("Connection established");
// Closing the connections
// using close() method
connection.close();
}
}
// Catch block to handle DB exceptions
catch (SQLException e)
{
// Display the line number where exception occurred
e.printStackTrace();
}
}
Output: Generated on console
Connection established
There are some common functions you'll be using after database connection:
Serve: For your application, you need a server to host. The server runs the Java Servlets The easy and basic server you can use in java is Tomcat.
- Tomcat is a web server designed to serve files from the local system.
If you are using eclipse, you'll have to install a tomcat server of any version and need to add a path to the application. Then, you can easily run the webpages with the respective port number provided by tomcat that will act as a local host.
Similar Reads
Best Ways to Learn Web Development Technology Stack
Web Development is considered to be one of the most important skills in software development to excel in the career. Learning web development requires time, and patience as it is a very vast field, having different sides. In this article, we will provide the best way to learn web development with al
7 min read
Why to Choose Java For Backend Development?
Java is well known for its programming language which is an Independent platform that provides high-level Java applications, robustness, and secures your Java applications, and also follows Object-Oriented Programming Language. The founder of Java is James Gosling, in the year 1991 the language was
9 min read
10 Best Web Development Project Ideas For Beginners in 2024
Learning web development is an exciting journey that opens doors to lots of creative possibilities. But for beginners, figuring out where to start with projects can be tricky. This article provides you with the Top 10 web development project ideas that are perfect for sharpening your skills in 2024.
7 min read
100 Days of Web Development - A Complete Guide For Beginners
How to become Web Developer? What is the salary of a Web Developer?What are the skills required to become a web developer? How many days will it take to become a web developer?To answer all these questions and give you a correct pathway, we have come up with 100 Days of Web Development that will gui
7 min read
Top 7 Programming Languages for Backend Web Development
Even if you're a beginner the least you would have known is that Web Development is majorly classified into two facets: Frontend Development and Backend Development. And obviously, they both have their respective set of tools and technologies. For instance, when we talk about Frontend Development, t
8 min read
7 Best Testing Frameworks for Java Developers
Java is one of the most popular languages for programming & development and a wide range of applications is developed in this particular language. And when an individual opts for making a career in Java, he is required to acquire the knowledge of testing frameworks also to develop secure and eff
5 min read
Top 10 Most Popular Java Frameworks for Web Development
Do you know more than 50 million websites including some most popular ones like Google, LinkedIn, eBay, Amazon, and Stack Overflow are written extensively using which language? the answer is nothing other than the most popular Java. Java just reached its Silver Anniversary but Still Ruling the softw
7 min read
JavaScript or Ruby - Which is Best for Beginners ?
There are many languages that are quite popular in the market and are widely used such as Python, Go, Java, Ruby, PHP, Kotlin, and many more. In this article, we will learn about Ruby which is a purely object-oriented, and general-purpose programming language JavaScript which is a high-level scripti
5 min read
Begin Web Development with a Head Start
To get a head start in web development, you can take the following steps: Learn the basics: Learn the basics of HTML, CSS, and JavaScript, which are the building blocks of web development. You can use online tutorials and resources, such as Codecademy, W3Schools, and FreeCodeCamp to start learning.
8 min read
Best Books To Learn Java For Beginners and Experts
To learn the art of programming in Java, it is important to first learn the rules and then learn when to break them! And this is important because Java is one of the most popular programming languages in the world as it can be used to design customized applications for a variety of purposes. Accordi
6 min read