Você está na página 1de 4

Ex. No.

: 1
Date:
Car Show Room Inventory – Web Application Using JSP and JDBC
Aim
To develop a car show room inventory web application using JSP and JDBC.
Algorithm
Step 1: Choose File > New Project from the main menu. Under categories select java
web,
under the project select web application then click Next.
Step 2: Give a name to the project and specify the project location to a directory on
the
computer.
Step 3: In the server and setting panel, specify the Glassfish Server on Tomcat as
server
which will be used to run the application.
Step 4: In the java EE version field, select Java EE5 click Finish.
Step 5: Create pages index.jsp and response.jsp and insert code for user interface.
Step 6: Create a style sheet to enhance to the design of the web page.
Step 7: Insert code to prepare communication between the application and database.
Step 8: Save project and run the application.
SOURCE CODE
index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="carshowroom.css">
<title>CarShowRoom Inventory</title>
</head>
<body>
<h1> Welcome To Honda Showroom! </h1>
<table border="0">
<thead>
<tr>
<th> Honda car India is a subsidiary of the honda of japan for the
production, marketing and export of passenger car in india</th>
</tr>
</thead>
<tbody>
<tr>
<td>To view details of car models, select an option below:</td>
</tr>
<tr>
<td>
<form action="response.jsp" method="POST">
<strong>select an option:</strong>
<select name="car_id">
<option>Honda City</option>
<option>Honda civic</option>
</select>
<input type="submit" value="Submit" />
</form> </td>
</tr>
</tbody>
</table>
</body>
</html>
response.jsp
<%@page import="java.sql.DriverManager"%>
<%@page language="java" session="true"
isThreadSafe="true"contentType="text/html"
pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="carshowroom.css">
<title>Car Details</title>
</head>
<body>
<table border="0">
<thead>
<tr>
<th>Honda Cars India</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<%
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =
DriverManager.getConnection("jdbc:odbc:HondaCar", "", "");
Statement stmt = con.createStatement();
String name=request.getParameter("car_id");
String s = "select * from car_details where cname='"+name+"'";
ResultSet r = stmt.executeQuery(s);
if (r.next()) {
out.println("Model Name:" + r.getString("cname"));
out.println("</td></tr>");
out.println("<tr><td>");
out.println("Cost:" + r.getString("cost"));
out.println("</td></tr>");
out.println("<tr><td>");
out.println("Milage:"+r.getString("milage"));
out.println("</td></tr>");
out.println("<tr><td>");
out.println("Color:"+r.getString("color"));
}
con.close();
} catch (Exception ex) {
out.println(ex);
}
%>
</tbody>
</table>
</body>
</html>
style.css
body
{
font-family:Veranda,Arial,Sans-serif;
font-size: smaller;
padding:50px;
color:#555;
}
h1{
text-align: left;
letter-spacing: 6px;
font-size: 1.4em;
color:#be7429;
font-weight:normal;
widht:450px;
}
table{ widht:580px;
padding:10px;
background-color: #c4e7e0;
}
th{
text-align: left;
border-bottom: 1px solid;
}
td{
padding: 10px;
}
OUTPUT:-

Result
Thus the above program car show room inventory was executed successfully
using JSP and JDBC connectivity

Você também pode gostar