· 7 years ago · Oct 28, 2018, 12:04 PM
1Code:
2<!DOCTYPE html>
3<html>
4<head>
5<title>This is my Resume.</title>
6<h1 style="font-family:Copperplate Gothic Light"><u>Resume</u></h1>
7<img src="C:\Users\16BCE0666\Downloads\download.png" alt="Profile Picture" border="2" style="float:right" height="120px" width="90px">
8<br>
9Name: Abhishek Vashisht<br>
10Registration Number: 16BCE0666<br>
11Email: abhivashisht98@gmail.com<br>
12Phone NO: 7530003883</br>
13<body style="background-color:MistyRose ">
14<!-- Desciption of Author: Abhishek Vashisht, Student of VIT University, III year, Computer Science Branch -->
15<!-- Date: 16th July 2018 -->
16<!-- Description: Resume of Abhishek Vashisht -->
17<h2>Objective</h2>
18<p>My short term goal is to score as much good in my unviersity as I can so that I get a super dream placement.
19I want to be good position at a large firm and earn good money for few years so that I can finance my MBA, which I am planning to do from outside India,
20so that I can get even better job.</p>
21<h2>Educational Qualifications</h2>
22<table border = "1">
23<tr>
24<th>Educational Institution</th>
25<th>Course</th>
26<th>Year</th>
27</tr>
28<tr>
29<td>Vivekanand School</td>
30<td>Schooling</td>
31<td>2002-2016</td>
32</tr>
33<tr>
34<td>VIT University</td>
35<td>B. Tech</td>
36<td>2016-Present</td>
37</tr>
38</table>
39<h2>Hobbies</h2>
40<ul>
41<li>Gaming<br><a href="https://www.store.steampowered.com">The place where I find all my games</a></li>
42<li>Coding<br><a href="https://www.w3schools.com/html/">The place where I learn all coding stuff</a></li>
43<li>Watching Movies<br><a href="https://yts.am">The place I download movies</a></li>
44</ul>
45</body>
46</html>
47
48Code:
49<!DOCTYPE html>
50<html>
51<head><title>Registration Form</title></head>
52<body>
53<form>
54<fieldset>
55<legend>Personal information:</legend>
56Email:<br>
57<input type="email" name="Email"><br>
58User Password:<br>
59<input type="password" name="password"><br>
60Gender:<br>
61<input list="gender">
62<datalist id="gender">
63<option value="Male">
64<option value="Female">
65<option value="Other">
66</datalist><br>
67Date Of Birth:<br>
68<input type="date" name="dob">
69</fieldset>
70<br>
71<fieldset>
72<legend>Preferences:</legend>
73Favourite Color:
74<input type="radio" name="color" value="red" checked> Red
75<input type="radio" name="color" value="orange" > Orange
76<input type="radio" name="color" value="blue" > Blue
77<input type="radio" name="color" value="other" > Other <br><br>
78Interested in: <br>
79<input type="text" name="interests"><br><br>
80Language:<br>
81<input list="language">
82<datalist id="language">
83<option value="English">
84<option value="Hindi">
85<option value="Other">
86</datalist><br>
87</fieldset>
88<br>
89<fieldset>
90<legend>Comment:</legend>
91About yourself: <br>
92<textarea name="message" rows="10" cols="30">
93</textarea><br><br>
94Upload Picture: <br>
95<input type="file" name="picture">
96<input type="submit" value="Submit">
97</fieldset>
98</form>
99</body>
100</html>
101
102Code:
103<!DOCTYPE html>
104<html>
105<head>
106<title>Form</title>
107<style>
108input[type=text], select {
109width: 220px;
110padding: 10px 10px;
111margin: 8px 0;
112display: inlineâ€block;
113border: 2px solid green;
114boxâ€sizing: borderâ€box;
115}
116input[type=date] {
117width: 220px;
118padding: 10px 10px;
119margin: 8px 0;
120display: inlineâ€block;
121border: 2px solid green;
122boxâ€sizing: borderâ€box;
123}
124input[type=text2] {
125width: 465px;
126padding: 10px 10px;
127margin: 8px 0;
128display: inlineâ€block;
129border: 2px solid green;
130boxâ€sizing: borderâ€box;
131}
132input[type=submit] {
133width: 50%;
134backgroundâ€color: #228B22;
135color: white;
136padding: 10px 10px;
137margin: 8px 0;
138border: none;
139borderâ€radius: 1px;
140cursor: pointer;
141}
142input[type=submit]:hover {
143backgroundâ€color: #45a049;
144}
145div {
146borderâ€radius: 25px;
147border: 2px solid #73AD21;
148background: #87CEFA;
149padding: 10px;
150width: 500px;
151height: 620px;
152textâ€align: center;
153margin: auto;
154fontâ€family: "Times New Roman", Times, serif;
155}
156div2{
157width: 220px;
158padding: 8px 8px;
159margin: 8px 0;
160display: inlineâ€block;
161border: 2px solid green;
162background: #87CEFA;
163textâ€align: right;
164fontâ€weight: bold;
165}
166</style>
167<body>
168<div>
169<form action="/action_page.php">
170<h2>Course Information</h2>
171<label for="name"><div2>Name</div2></label>
172<input type="text" id="name" name="name">
173<br>
174<label for="Email"><div2>Email</div2></label>
175<input type="text" id="email" name="email">
176<br>
177<label for="Gender"><div2>Gender</div2></label>
178<select id="gender" name="gender">
179<option value="Male">Male</option>
180<option value="Female">Female</option>
181<option value="Other">Other</option>
182</select>
183<br>
184<label for="DOB"><div2>Date of birth</div2></label>
185<input type="date" id="dob" name="dob">
186<br>
187<label for="Cname"><div2>Course Name</div2></label>
188<input type="text" id="cname" name="cname">
189<br>
190<label for="Ccode"><div2>Course code</div2></label>
191<input type="text" id="ccode" name="ccode">
192<br>
193<label for="Slot"><div2>Slot</div2></label>
194<select id="slot" name="slot">
195<option value="first">L23+L24</option>
196<option value="second">L29+L30</option>
197<option value="third">L59+L60</option>
198</select>
199<br>
200<label for="Mob"><div2>Mobile Mumber</div2></label>
201<input type="text" id="mob" name="mob">
202<br>
203<input type="text2" id="remarks" name="remarks" placeholder="Remarks">
204<br>
205<input type="submit" value="Submit">
206</form>
207</div>
208</body>
209</html>
210
211Code:
212<!DOCTYPE html>
213<html>
214<head>
215<title>Form</title>
216<style>
217input[type=text],[type=password],[type=date],select{
218width: 220px;
219padding: 5px 10px;
220margin: 8px 0;
221display: inline-block;
222box-sizing: border-box;
223}
224[type=submit]{
225width: 80px;
226height: 30px;
227padding: 3px 3px;
228margin: 8px 0;
229display: inline-block;
230box-sizing: border-box;
231font-size: 15px;
232}
233#p1{
234color:white;
235}
236#p2{
237margin-top: -7px;
238color:white;
239}
240div {
241border: 15px solid #000000;
242background: #696969 ;
243padding: 10px;
244width: 500px;
245height: 330px;
246text-align: left;
247margin: auto;
248font-family: "Times New Roman", Times, serif;
249}
250div2{
251width: 150px;
252padding: 8px 8px;
253margin: 0 0;
254display: inline-block;
255background: #696969;
256text-align: left;
257color: #FFFFFF;
258}
259input:valid {
260background-color: lightgreen;
261}
262input:invalid {
263background-color: lightcoral;
264}
265</style>
266<body background:#DCDCDC>
267<div>
268<form name="forrrm">
269<label for="login"><div2>Login</div2></label>
270<input type="text" id="login" name="login" pattern=".{8,}" title="Minimum 8 characters required" required>
271<br>
272<label for="password"><div2>Password</div2></label>
273<input type="password" id= "password" name="password" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{16,}" title="Minimum 16 characters with atleast 1 digit, 1 uppercase and 1 lowercase" required>
274<br>
275<label for="cpassword"><div2>Confirm Password</div2></label>
276<input type="password" id="cpassword" name="cpassword" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{16,}" required>
277<br>
278<label for="Gender"><div2>Gender</div2></label>
279<select id="gender" name="gender">
280<option value="Male">Male</option>
281<option value="Female">Female</option>
282<option value="Other">Other</option>
283</select>
284<br>
285<label for="Email"><div2>Email</div2></label>
286<input type="text" id="email" name="email" pattern="(?=.*@).{1,}" title="Minimum one @ symbol" required>
287<br>
288<input type="submit" value="Register" onclick="myfunc()" style="background-color:white !important;" required>
289</form>
290<p id="p1"></p>
291<p id="p2"></p>
292</div>
293<script>
294function myfunc(){
295var x=document.forms["forrrm"]["password"].value;
296var y=document.forms["forrrm"]["cpassword"].value;
297var z=document.forms["forrrm"]["email"].value;
298if (x!=y){
299document.getElementById("p1").innerHTML="Passwords are not the same";
300}
301else{
302document.getElementById("p1").innerHTML="";
303}
304var i;
305for(i=0;i<z.length;i++){
306if(z[i]=='@'){
307document.getElementById("p2").innerHTML="";
308}
309else{
310document.getElementById("p2").innerHTML="Mail is Wrong";
311}
312}}
313</script>
314</body>
315</html>
316
317<!DOCTYPE html>
318<html>
319<head>
320<title>Form</title>
321<style>
322.error {color: red;}
323input[type=text],[type=password],[type=date],[type=submit],select{
324width: 220px;
325padding: 5px 10px;
326margin: 8px 0;
327display: inline-block;
328box-sizing: border-box;
329}
330div {
331border: 15px solid #000000;
332background: #696969 ;
333padding: 10px;
334width: 500px;
335height: 400px;
336text-align: left;
337margin: auto;
338font-family: "Times New Roman", Times, serif;
339}
340div2{
341width: 150px;
342padding: 8px 4px;
343margin: 0 0;
344display: inline-block;
345background: #696969;
346text-align: left;
347color: #FFFFFF;
348}
349</style>
350</head>
351<body>
352<?php
353$usernameErr = $emailErr = $passwordErr = $cpasswordErr = $matchErr = $errors_init = "";
354$username = $email = $password = $cpassword = "";
355if ($_SERVER["REQUEST_METHOD"] == "POST") {
356if (empty($_POST["username"])) {
357$usernameErr = "Username is required";
358} else {
359$username = test_input($_POST["username"]);
360if (!preg_match("/.{8,}/",$username)) {
361$usernameErr = "Minimum 8 characters";
362}
363}
364if (empty($_POST["password"])) {
365$passwordErr = "Password is required";
366} else {
367$password = test_input($_POST["password"]);
368if (!preg_match("/.{16,}/", $password)) {
369$passwordErr = "Password too short!";
370}
371if (!preg_match("/[0-9]+/", $password)) {
372$passwordErr = "Password must include at least one number!";
373}
374if (!preg_match("/[a-z]+/", $password)) {
375$passwordErr = "Password must include at least one lowercase!";
376}
377if (!preg_match("/[A-Z]+/", $password)) {
378$passwordErr = "Password must include at least one uppercase!";
379}
380}
381if (empty($_POST["cpassword"])) {
382$cpasswordErr = "Password is required";
383} else {
384$cpassword = test_input($_POST["cpassword"]);
385}
386if (empty($_POST["email"])) {
387$emailErr = "Email is required";
388} else {
389$email = test_input($_POST["email"]);
390if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
391$emailErr = "Invalid email format";
392}
393}
394if($_POST['password']!= $_POST['cpassword']) {
395$matchErr = "Passwords do not match";
396}
397}
398function test_input($data) {
399$data = trim($data);
400$data = stripslashes($data);
401$data = htmlspecialchars($data);
402return $data;
403}
404?>
405<div>
406<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
407<label for="username"><div2>Username</div2></label>
408<input type="text" id="username" name="username" value="<?php echo $username;?>">
409<span class="error">*<br> <?php echo $usernameErr;?></span>
410<br>
411<label for="password"><div2>Password</div2></label>
412<input type="password" id="password" name="password" value="<?php echo $password;?>">
413<span class="error">* <br> <?php echo $passwordErr;?></span>
414<br>
415<label for="cpassword"><div2>Confirm Password</div2></label>
416<input type="password" id="cpassword" name="cpassword" value="<?php echo $cpassword;?>">
417<span class="error">* <br> <?php echo $cpasswordErr;?></span>
418<br>
419<label for="Gender"><div2>Gender</div2></label>
420<select id="gender" name="gender">
421<option value="Male">Male</option>
422<option value="Female">Female</option>
423<option value="Other">Other</option>
424</select><span class="error"> *</span>
425<br><br>
426<label for="Email"><div2>Email</div2></label>
427<input type="text" id="email" name="email" value="<?php echo $email;?>">
428<span class="error">*<br> <?php echo $emailErr;?></span>
429<br>
430<input type="submit" value="Register"><br>
431<span class="error"><?php echo $matchErr;?></span>
432</form>
433</div>
434</body>
435</html>
436
437Code:
438<!DOCTYPE html>
439<html>
440<head>
441<title>Course Registration</title>
442<style>
443.centered {
444position: absolute;
445top: 30%;
446text-align: center;
447left: 50%;
448transform: translate(-50%, -50%);
449}
450img{
451opacity:0.2;
452}
453th{
454background-color: LightGray;
455}
456table{
457border-spacing:0px;
458}
459#cat{
460margin-top:50px;
461}
462h1{
463font-size:2.5em;
464font-weight: bold;
465}
466h2{
467font-size:2.2em;
468}
469.container{
470position: relative;
471text-align: center;
472margin: -10px;
473/*margin-top: -10px;*/
474}
475body{
476font-family: "arial";
477}
478</style>
479</head>
480<body>
481<center>
482<div class="container">
483<img src="slider.jpg" width="100%" height="100%">
484<div class="centered">
485<h1 style="color:green">CAT EXAM PROCESS</h1>
486<h1 style="color:blue">SCOPE</h1>
487<h2 style="color:blue">VIT UNIVERSITY, VELLORE</h2>
488<table border="1" bgcolor="white" width="1200px">
489<tr>
490<th>Slot</th>
491<th>Course Code</th>
492<th>Course Name</th>
493<th>Faculty ID</th>
494<th>Reg No</th>
495<th>Name</th>
496<th>Faculty Name</th>
497<th>Program</th>
498<th>Branch</th>
499</tr>
500<?php
501$con = mysqli_connect("localhost","scse","scse","scse");
502$sql = "select * from exam";
503$result = mysqli_query($con,$sql);
504for($j=0;$j<mysqli_num_rows($result);$j++)
505{
506$row = mysqli_fetch_array($result);?>
507<tr>
508<td><?php echo $row[0]?></td>
509<td><?php echo $row[1]?></td>
510<td><?php echo $row[2]?></td>
511<td><?php echo $row[3]?></td>
512<td><?php echo $row[4]?></td>
513<td><?php echo $row[5]?></td>
514<td><?php echo $row[6]?></td>
515<td><?php echo $row[7]?></td>
516<td><?php echo $row[8]?></td>
517</tr>
518<?php
519}
520?>
521</table>
522</div>
523</div>
524</center>
525</body>
526</html>
527
528Code:
529form.html
530<!DOCTYPE html>
531<html>
532<head>
533<title>PHP File upload</title>
534<style>
535div2{
536margin-top: 3px;
537width: 450px;
538padding-left: 10px;
539padding-right: 10px;
540}
541div{
542width: 500px;
543background-color: gainsboro;
544margin: auto;
545padding: 20px;
546font-weight: bold;
547}
548#fname,#lname{
549width:205px;
550margin-right: 10px;
551}
552#day{
553width: 70px;
554margin-right: 10px;
555}
556#year{
557width: 160px
558}
559#month{
560width: 170px;
561margin-right: 10px;
562padding-left: 10px;
563background-color: gainsboro;
564}
565input[type=text],[type=email],[type=password]{
566margin-top: 3px;
567width: 450px;
568padding-left: 10px;
569padding-right: 10px;
570}
571#gender{
572padding-left: 10px;
573margin-top: 3px;
574background-color: gainsboro;
575width: 470px;
576}
577#location{
578padding-left: 10px;
579margin-top: 3px;
580background-color: gainsboro;
581width: 470px;
582}
583</style>
584</head>
585<body>
586<div>
587<form action="upload_file.php" method="post" enctype="multipart/form-data">
588Name <br>
589<input type="text" id="fname" name="fname" placeholder="First">
590<input type="text" id="lname" name="lname" placeholder="Last">
591<br><br>
592Choose your username<br>
593<input type="text" id="username" name="username" placeholder="@gmail.com">
594<br><br>
595Create a password<br>
596<input type="password" name="password" id="password">
597<br><br>
598Confirm your password<br>
599<input type="password" name="cpassword" id="cpassword">
600<br><br>
601Birthday<br>
602<select id="month" name="month" >
603<option value="">Month</option>
604<option value="January">January</option>
605<option value="February">February</option>
606<option value="March">March</option>
607<option value="April">April</option>
608<option value="May">May</option>
609<option value="June">June</option>
610<option value="July">July</option>
611<option value="August">August</option>
612<option value="Septmeber">Septmeber</option>
613<option value="October">October</option>
614<option value="November">November</option>
615<option value="December">December</option>
616</select>
617<input type="text" name="day" id="day" placeholder="Day">
618<input type="text" name="year" id="year" placeholder="Year">
619<br><br>
620Gender<br>
621<select id="gender" name="gender">
622<option value="Male">I am...</option>
623<option value="Male">Male</option>
624<option value="Female">Female</option>
625<option value="Other">Other</option>
626</select><br><br>
627Mobile Phone<br>
628<input type="text" name="mobile" id="mobile" placeholder="+91">
629<br><br>
630Your current email address<br>
631<input type="email" name="email" id="email">
632<br><br>
633Location<br>
634<select id="location" name="location">
635<option value="Afghanistan">Afghanistan</option><option value="Yemen">Yemen</option><option value="Zaire">Zaire</option><option value="Zambia">Zambia</option><option value="Zimbabwe">Zimbabwe</option></select><br><br>
636Photo:
637<input type="file" name="file" id="file">
638<br><br>
639<input type="submit" name="submit" value="Submit">
640</form>
641</div>
642</body>
643</html>
644
645upload_file.php
646<?php
647$allowedExts = array("gif", "jpeg", "jpg", "png");
648$temp = explode(".", $_FILES["file"]["name"]);
649$extension = end($temp);
650if ((($_FILES["file"]["type"] == "image/gif")
651|| ($_FILES["file"]["type"] == "image/jpeg")
652|| ($_FILES["file"]["type"] == "image/jpg")
653|| ($_FILES["file"]["type"] == "image/pjpeg")
654|| ($_FILES["file"]["type"] == "image/x-png")
655|| ($_FILES["file"]["type"] == "image/png"))
656&& in_array($extension, $allowedExts)) {
657if (file_exists("Saved_File/" . $_FILES["file"]["name"])){
658$uploaded="Already Exists";
659}
660else{
661move_uploaded_file($_FILES["file"]["tmp_name"],"Saved_File/" . $_FILES["file"]["name"]);
662$uploaded="File uploaded";
663}
664}
665else
666{
667$uploaded="Invalid File";
668}
669?>
670<table border="1">
671<tr>
672<th>First Name</th>
673<th>Last Name</th>
674<th>Username</th>
675<th>Birthday</th>
676<th>Gender</th>
677<th>Mobile Number</th>
678<th>Current Email address</th>
679<th>Location</th>
680<th>Photo Upload Status</th>
681</tr>
682<?php
683if (empty($_POST["fname"])) {
684$fn = "No input";
685}
686else
687$fn=$_POST['fname'];
688if (empty($_POST["lname"])) {
689$ln = "No input";
690}
691else
692$ln=$_POST['lname'];
693if (empty($_POST["username"])) {
694$un = "No input";
695}
696else
697$un=$_POST['username'];
698if (empty($_POST["day"])||empty($_POST["year"])||empty($_POST["month"])) {
699$birthday = "No or incomplete input";
700}
701else {
702$day=$_POST['day'];
703$year=$_POST['year'];
704$month=$_POST['month'];
705$birthday=$day."/".$month."/".$year;
706}
707if (empty($_POST["gender"])) {
708$gd = "No input";
709}
710else
711$gd=$_POST['gender'];
712if (empty($_POST["mobile"])) {
713$mb = "No input";
714}
715else
716$mb=$_POST['mobile'];
717if (empty($_POST["email"])) {
718$email = "No input";
719}
720else
721$email=$_POST['email'];
722if (empty($_POST["location"])) {
723$loc = "No input";
724}
725else
726$loc=$_POST['location'];
727?>
728<tr>
729<td><?php echo $fn?></td>
730<td><?php echo $ln?></td>
731<td><?php echo $un?></td>
732<td><?php echo $birthday?></td>
733<td><?php echo $gd?></td>
734<td><?php echo $mb?></td>
735<td><?php echo $email?></td>
736<td><?php echo $loc?></td>
737<td><?php echo $uploaded?></td>
738</tr></table>
739
740Code:
741Index.html
742<!DOCTYPE html>
743<html>
744<head>
745<title>Form</title>
746<style>
747input[type=text], select {
748width: 220px;
749padding: 10px 10px;
750margin: 8px 0;
751display: inline-block;
752border: 2px solid black;
753box-sizing: border-box;
754}
755input[type=date] {
756width: 220px;
757padding: 10px 10px;
758margin: 8px 0;
759display: inline-block;
760border: 2px solid black;
761box-sizing: border-box;
762}
763input[type=text2] {
764width: 465px;
765padding: 10px 10px;
766margin: 8px 0;
767display: inline-block;
768border: 2px solid black;
769box-sizing: border-box;
770}
771input[type=submit] {
772width: 50%;
773background-color: #228B22;
774color: white;
775padding: 10px 10px;
776margin: 8px 0;
777border: none;
778border-radius: 1px;
779cursor: pointer;
780}
781input[type=submit]:hover {
782background-color: #45a049;
783}
784div {
785border-radius: 15px;
786border: 2px solid black;
787background: lightcoral;
788padding: 10px;
789width: 500px;
790height: 520px;
791text-align: center;
792margin: auto;
793font-family: "Times New Roman", Times, serif;
794}
795div2{
796width: 220px;
797padding: 8px 8px;
798margin: 8px 0;
799display: inline-block;
800border: 2px solid black;
801background: lightgrey;
802text-align: left;
803font-weight: bold;
804}
805</style>
806<body>
807<div>
808<form name="RegForm" method="post" action="NewServlet">
809<h2>Convocation Form</h2>
810<div2>Name</div2>
811<input type="text" id="name" name="name" required>
812<br>
813<div2>Email</div2>
814<input type="text" id="email" name="email" pattern="(?=.*@).{1,}" title="Minimum one @ symbol" required>
815<br>
816<div2>Gender</div2>
817<select id="gender" name="gender">
818<option value="Male">Male</option>
819<option value="Female">Female</option>
820<option value="Other">Other</option>
821</select>
822<br>
823<div2>Date of birth</div2>
824<input type="date" id="dob" name="dob" required>
825<br>
826<div2>Programme Name</div2>
827<input type="text" id="cname" name="pname" required>
828<br>
829<div2>Mobile Mumber</div2>
830<input type="text" id="mob" name="mob" pattern="(?=.*\d).{10}" required>
831<br>
832<div2>Address</div2>
833<input type="text" id="add" name="add" required>
834<br>
835<input type="submit" value="Submit">
836</form>
837</div>
838</body>
839</html>
840Web.xml
841<?xml version="1.0" encoding="UTF-8"?>
842<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
843<servlet>
844<servlet-name>NewServlet</servlet-name>
845<servlet-class>NewServlet</servlet-class>
846</servlet>
847<servlet-mapping>
848<servlet-name>NewServlet</servlet-name>
849<url-pattern>/NewServlet</url-pattern>
850</servlet-mapping>
851<welcome-file-list>
852<welcome-file>index.html</welcome-file>
853</welcome-file-list>
854</web-app>
855NewSevlet.java
856/*
857* To change this license header, choose License Headers in Project Properties.
858* To change this template file, choose Tools | Templates
859* and open the template in the editor.
860*/
861import java.io.IOException;
862import java.io.PrintWriter;
863import javax.servlet.ServletException;
864import javax.servlet.http.HttpServlet;
865import javax.servlet.http.HttpServletRequest;
866import javax.servlet.http.HttpServletResponse;
867/**
868*
869* @author 16BCE0666
870*/
871public class NewServlet extends HttpServlet {
872/**
873* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
874* methods.
875*
876* @param request servlet request
877* @param response servlet response
878* @throws ServletException if a servlet-specific error occurs
879* @throws IOException if an I/O error occurs
880*/
881protected void processRequest(HttpServletRequest request, HttpServletResponse response)
882throws ServletException, IOException {
883response.setContentType("text/html;charset=UTF-8");
884String name = request.getParameter("name");
885String email = request.getParameter("email");
886String gender = request.getParameter("gender");
887String dob = request.getParameter("dob");
888String pname = request.getParameter("pname");
889String mob = request.getParameter("mob");
890String add = request.getParameter("add");
891PrintWriter writer=response.getWriter();
892String htmlResponce="<html>";
893htmlResponce+="<h1>Name :"+name;
894htmlResponce+="<br>";
895htmlResponce+="Email :"+email;
896htmlResponce+="<br>";
897htmlResponce+="Gender :"+gender;
898htmlResponce+="<br>";
899htmlResponce+="Date of Birth :"+dob;
900htmlResponce+="<br>";
901htmlResponce+="Programme Name :"+pname;
902htmlResponce+="<br>";
903htmlResponce+="Mobile Number :"+mob;
904htmlResponce+="<br>";
905htmlResponce+="Address :"+add;
906htmlResponce+="<br>";
907htmlResponce+="REGISTRATION SUCCESSFUL</h1>";
908htmlResponce+="</html>";
909writer.println(htmlResponce);
910}
911// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
912/**
913* Handles the HTTP <code>GET</code> method.
914*
915* @param request servlet request
916* @param response servlet response
917* @throws ServletException if a servlet-specific error occurs
918* @throws IOException if an I/O error occurs
919*/
920@Override
921protected void doGet(HttpServletRequest request, HttpServletResponse response)
922throws ServletException, IOException {
923processRequest(request, response);
924}
925/**
926* Handles the HTTP <code>POST</code> method.
927*
928* @param request servlet request
929* @param response servlet response
930* @throws ServletException if a servlet-specific error occurs
931* @throws IOException if an I/O error occurs
932*/
933@Override
934protected void doPost(HttpServletRequest request, HttpServletResponse response)
935throws ServletException, IOException {
936processRequest(request, response);
937}
938/**
939* Returns a short description of the servlet.
940*
941* @return a String containing servlet description
942*/
943@Override
944public String getServletInfo() {
945return "Short description";
946}// </editor-fold>
947}
948
949CODES
950index.html
951<!DOCTYPE html>
952<!--
953To change this license header, choose License Headers in Project Properties.
954To change this template file, choose Tools | Templates
955and open the template in the editor.
956-->
957<html>
958<head>
959<title>Airways Ticket Booking</title>
960<meta charset="UTF-8">
961<meta name="viewport" content="width=device-width, initial-scale=1.0">
962<style>
963select {
964width: 220px;
965padding: 10px 10px;
966margin: 8px 0;
967display: inline-block;
968border: 2px solid black;
969box-sizing: border-box;
970}
971input[type=date] {
972width: 220px;
973padding: 10px 10px;
974margin: 8px 0;
975display: inline-block;
976border: 2px solid black;
977box-sizing: border-box;
978}
979input[type=submit] {
980width: 50%;
981background-color: #228B22;
982color: white;
983padding: 10px 10px;
984margin: 8px 0;
985border: none;
986border-radius: 1px;
987cursor: pointer;
988}
989input[type=submit]:hover {
990background-color: #45a049;
991}
992div {
993border-radius: 15px;
994border: 2px solid black;
995background: lightcoral;
996padding: 10px;
997width: 500px;
998height: 350px;
999text-align: center;
1000margin: auto;
1001font-family: "Times New Roman", Times, serif;
1002}
1003#p1{
1004color:white;
1005}
1006div2{
1007width: 220px;
1008padding: 8px 8px;
1009margin: 8px 0;
1010display: inline-block;
1011border: 2px solid black;
1012background: lightgrey;
1013text-align: left;
1014font-weight: bold;
1015}
1016body{
1017background-color: LightBlue;
1018}
1019</style>
1020</head>
1021<body>
1022<div>
1023<form name="Air" method="post" action="NewServlet">
1024<h2>Airways Ticket Booking</h2>
1025<div2>Select Origin </div2>
1026<select id="origin" name="origin">
1027<option value="Delhi">Delhi</option>
1028<option value="Chennai">Chennai</option>
1029</select><br>
1030<div2>Select Destination</div2>
1031<select id="destination" name="destination">
1032<option value="Delhi">Delhi</option>
1033<option value="Chennai">Chennai</option>
1034</select><br>
1035<div2>Select date</div2>
1036<input type="date" name='date' id='date' required>
1037<br><input type='submit' value='Search'>
1038</form>
1039<p id="p1">Select Dates between 01-11-2018 and 10-11-2018 (both inclusive)</p>
1040</div>
1041</body>
1042</html>
1043
1044NewServlet.java
1045/*
1046* To change this license header, choose License Headers in Project Properties.
1047* To change this template file, choose Tools | Templates
1048* and open the template in the editor.
1049*/
1050import java.io.IOException;
1051import java.io.PrintWriter;
1052import java.sql.Connection;
1053import java.sql.DriverManager;
1054import java.sql.PreparedStatement;
1055import java.sql.ResultSet;
1056import java.sql.SQLException;
1057import java.sql.Statement;
1058import javax.servlet.ServletException;
1059import javax.servlet.http.HttpServlet;
1060import javax.servlet.http.HttpServletRequest;
1061import javax.servlet.http.HttpServletResponse;
1062/**
1063*
1064* @author deepalakshmi
1065*/
1066public class NewServlet extends HttpServlet {
1067/**
1068* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
1069* methods.
1070*
1071* @param request servlet request
1072* @param response servlet response
1073* @throws ServletException if a servlet-specific error occurs
1074* @throws IOException if an I/O error occurs
1075*/
1076protected void processRequest(HttpServletRequest request, HttpServletResponse response)
1077throws ServletException, IOException {
1078response.setContentType("text/html;charset=UTF-8");
1079try (PrintWriter out = response.getWriter()) {
1080/* TODO output your page here. You may use following sample code. */
1081String origin = request.getParameter("origin");
1082String destination = request.getParameter("destination");
1083String date = request.getParameter("date");
1084String connectionURL = "jdbc:derby://localhost:1527/Airway";
1085PrintWriter writer=response.getWriter();
1086try {
1087if (origin == null ? destination != null : !origin.equals(destination))
1088{
1089Connection conn = DriverManager.getConnection(connectionURL, "air", "air");
1090String htmlResponce="<html><head><title>Airways Ticket Booking</title>";
1091htmlResponce+="<style>";
1092htmlResponce+="body {\n" +
1093" background-color: lightblue;\n" +
1094"}";
1095htmlResponce+="th{\n" +
1096"background-color: LightGray;\n" +
1097"vertical-align: middle;\n" +
1098"height: 60px;\n" +
1099"}\n" +
1100"table{\n" +
1101"border-spacing:0px;\n" +
1102"}";
1103htmlResponce+="td{\n" +
1104"background-color: LemonChiffon;\n" +
1105"height: 40px;\n" +
1106"text-align:center;\n" +
1107"}";
1108htmlResponce+="</style></head>";
1109htmlResponce+="<body><center><h1>Search Results</h1><br>";
1110String sql = "SELECT * FROM flights where origin=? and destination=? and date=?";
1111PreparedStatement ps = conn.prepareStatement(sql);
1112ps.setString(1,origin);
1113ps.setString(2,destination);
1114ps.setString(3,date);
1115Statement st = conn.createStatement();
1116ResultSet rs=null;
1117rs=ps.executeQuery();
1118htmlResponce+="<table border=1px width=1000px>";
1119htmlResponce+="<tr>";
1120htmlResponce+="<th><h2>Airlines</h2></th>";
1121htmlResponce+="<th><h2>Flight No.</h2></th>";
1122htmlResponce+="<th><h2>Departure</h2></th>";
1123htmlResponce+="<th><h2>Arrival</h2></th>";
1124htmlResponce+="<th><h2>Duration</h2></th>";
1125htmlResponce+="<th><h2>Price</h2></th>";
1126htmlResponce+="</tr>";
1127while(rs.next()){
1128htmlResponce+="<tr>";
1129htmlResponce+="<td>";
1130htmlResponce+=rs.getString("airlines");
1131htmlResponce+="</td>";
1132htmlResponce+="<td>";
1133htmlResponce+=rs.getString("flightno");
1134htmlResponce+="</td>";
1135htmlResponce+="<td>";
1136htmlResponce+=rs.getString("departure");
1137htmlResponce+="</td>";
1138htmlResponce+="<td>";
1139htmlResponce+=rs.getString("arrival");
1140htmlResponce+="</td>";
1141htmlResponce+="<td>";
1142htmlResponce+=rs.getString("duration");
1143htmlResponce+="</td>";
1144htmlResponce+="<td>";
1145htmlResponce+=rs.getString("price");
1146htmlResponce+="</td>";
1147htmlResponce+="</tr>";
1148}
1149rs.close();
1150st.close();
1151htmlResponce+="</table><center></body></html>";
1152writer.println(htmlResponce);
1153conn.close();
1154}
1155else{
1156String htmlResponce="<html><head><title>Airways Ticket Booking</title>";
1157htmlResponce+="<style>";
1158htmlResponce+="body {\n" +
1159" background-color: lightblue;\n" +
1160"}</style></head>";
1161htmlResponce+="<body><h2>Error: The destination and origin cannot be same</h2></body></html>";
1162writer.println(htmlResponce);
1163}
1164} catch (SQLException ex) {
1165out.println("Connect failed ! ");
1166}
1167}
1168}
1169// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
1170/**
1171* Handles the HTTP <code>GET</code> method.
1172*
1173* @param request servlet request
1174* @param response servlet response
1175* @throws ServletException if a servlet-specific error occurs
1176* @throws IOException if an I/O error occurs
1177*/
1178@Override
1179protected void doGet(HttpServletRequest request, HttpServletResponse response)
1180throws ServletException, IOException {
1181processRequest(request, response);
1182}
1183/**
1184* Handles the HTTP <code>POST</code> method.
1185*
1186* @param request servlet request
1187* @param response servlet response
1188* @throws ServletException if a servlet-specific error occurs
1189* @throws IOException if an I/O error occurs
1190*/
1191@Override
1192protected void doPost(HttpServletRequest request, HttpServletResponse response)
1193throws ServletException, IOException {
1194processRequest(request, response);
1195}
1196/**
1197* Returns a short description of the servlet.
1198*
1199* @return a String containing servlet description
1200*/
1201@Override
1202public String getServletInfo() {
1203return "Short description";
1204}// </editor-fold>
1205}
1206
1207web.xml
1208<?xml version="1.0" encoding="UTF-8"?>
1209<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
1210<servlet>
1211<servlet-name>NewServlet</servlet-name>
1212<servlet-class>NewServlet</servlet-class>
1213</servlet>
1214<servlet-mapping>
1215<servlet-name>NewServlet</servlet-name>
1216<url-pattern>/NewServlet</url-pattern>
1217</servlet-mapping>
1218<welcome-file-list>
1219<welcome-file>index.html</welcome-file>
1220</welcome-file-list>
1221</web-app>