├── README.md ├── jsp-jdbc-mysql-example ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ └── org.eclipse.wst.jsdt.ui.superType.name ├── WebContent │ ├── META-INF │ │ └── MANIFEST.MF │ ├── WEB-INF │ │ └── lib │ │ │ └── mysql-connector-java-8.0.13.jar │ ├── employeedetails.jsp │ └── employeeregister.jsp ├── build │ └── classes │ │ └── net │ │ └── javaguides │ │ └── jsp │ │ └── jdbc │ │ ├── bean │ │ └── Employee.class │ │ └── database │ │ └── EmployeeDao.class └── src │ └── net │ └── javaguides │ └── jsp │ └── jdbc │ ├── bean │ └── Employee.java │ └── database │ └── EmployeeDao.java ├── jsp-tutorial ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ └── org.eclipse.wst.jsdt.ui.superType.name ├── WebContent │ ├── META-INF │ │ └── MANIFEST.MF │ ├── WEB-INF │ │ ├── lib │ │ │ └── mysql-connector-java-8.0.13.jar │ │ └── message.tld │ ├── callingjavaclass.jsp │ ├── converter.jsp │ ├── database │ │ ├── employeedetails.jsp │ │ └── employeeregister.jsp │ ├── declarationtag.jsp │ ├── expressiontag.jsp │ ├── form │ │ ├── student-checkbox-form.html │ │ ├── student-checkbox-response.jsp │ │ ├── student-dropdown-form.html │ │ ├── student-dropdown-response.jsp │ │ ├── student-form.html │ │ ├── student-radio-form.html │ │ ├── student-radio-response.jsp │ │ └── student-response.jsp │ ├── helloworld.jsp │ ├── implicitobjects.jsp │ ├── include │ │ ├── footer.jsp │ │ └── header.jsp │ ├── index.jsp │ ├── jstl │ │ └── customtag.jsp │ ├── redirect │ │ ├── page1.jsp │ │ └── page2.jsp │ ├── request.jsp │ ├── scriptlets.jsp │ ├── student.jsp │ └── studentdetails.jsp ├── build │ └── classes │ │ └── net │ │ └── javaguides │ │ └── jsp │ │ └── tutorial │ │ ├── Calculator.class │ │ ├── Student.class │ │ ├── database │ │ ├── Employee.class │ │ └── EmployeeDao.class │ │ └── jstl │ │ └── CustomTag.class └── src │ └── net │ └── javaguides │ └── jsp │ └── tutorial │ ├── Calculator.java │ ├── Student.java │ ├── database │ ├── Employee.java │ └── EmployeeDao.java │ └── jstl │ └── CustomTag.java ├── jstl-tutorial ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ └── org.eclipse.wst.jsdt.ui.superType.name ├── WebContent │ ├── META-INF │ │ └── MANIFEST.MF │ ├── WEB-INF │ │ └── lib │ │ │ ├── javax.servlet.jsp.jstl-1.2.1.jar │ │ │ └── javax.servlet.jsp.jstl-api-1.2.1.jar │ ├── choose-student-test.jsp │ ├── foreach-simple-test.jsp │ ├── foreach-student-test.jsp │ ├── if-student-test.jsp │ ├── jstl-functions-examples.jsp │ └── test.jsp ├── build │ └── classes │ │ └── net │ │ └── javaguides │ │ └── jstl │ │ └── Student.class └── src │ └── net │ └── javaguides │ └── jstl │ └── Student.java ├── login-jsp-jdbc-example ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ └── org.eclipse.wst.jsdt.ui.superType.name ├── WebContent │ ├── META-INF │ │ └── MANIFEST.MF │ ├── WEB-INF │ │ └── lib │ │ │ └── mysql-connector-java-8.0.13.jar │ ├── login.jsp │ └── loginsuccess.jsp ├── build │ └── classes │ │ └── net │ │ └── javaguides │ │ └── login │ │ ├── bean │ │ └── LoginBean.class │ │ └── database │ │ └── LoginDao.class └── src │ └── net │ └── javaguides │ └── login │ ├── bean │ └── LoginBean.java │ └── database │ └── LoginDao.java └── registration-jsp-jdbc-example ├── .classpath ├── .project ├── .settings ├── .jsdtscope ├── org.eclipse.jdt.core.prefs ├── org.eclipse.wst.common.component ├── org.eclipse.wst.common.project.facet.core.xml ├── org.eclipse.wst.jsdt.ui.superType.container └── org.eclipse.wst.jsdt.ui.superType.name ├── WebContent ├── META-INF │ └── MANIFEST.MF ├── WEB-INF │ └── lib │ │ └── mysql-connector-java-8.0.13.jar ├── employeedetails.jsp └── employeeregister.jsp ├── build └── classes │ └── net │ └── javaguides │ └── registration │ ├── bean │ └── Employee.class │ └── database │ └── EmployeeDao.class └── src └── net └── javaguides └── registration ├── bean └── Employee.java └── database └── EmployeeDao.java /README.md: -------------------------------------------------------------------------------- 1 | # JSP-Tutorial 2 | Beginners to expert JSP Tutorial 3 | 4 | 5 |
6 | 14 | 15 |
16 |
17 |
18 | This tutorial has been prepared for the beginners to help them understand the basic functionality of Java Server Pages (JSP) to develop your web applications. After completing this tutorial you will find yourself at a moderate level of expertise in using JSP from where you can take yourself to next levels.
19 |

20 | Basic JSP Tutorial

21 |
22 |
23 | 26 | 29 | 32 | 35 | 38 | 41 | 44 | 47 | 50 | 53 | 56 | 59 | 62 | 65 | 68 |

69 | JSP + JDBC

70 |
71 |
72 |
73 |
    74 |
  • JSP + JDBC + MySQL Example -  In this article, we will build a simple Employee Registration module using JSPJDBC, and MySQL database.
  • 75 |
76 | 79 | 82 |

83 | JSTL Tutorial

84 |
85 |

86 | JSP Custom Tag Development

87 |
88 |
    89 |
90 |
91 |
92 |
93 |
    94 |
  • JSP Custom Tag Development - In this tutorial, we will learn how to create a simple JSP custom tag and how to use it in JSP. Custom tags are user-defined tags.
  • 95 |
96 | 99 |
100 |

101 | JSTL Tags from JSTL Libraries

102 |
103 |
104 | 107 | 110 | 113 |
114 |
115 |
116 | -------------------------------------------------------------------------------- /jsp-jdbc-mysql-example/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /jsp-jdbc-mysql-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jsp-jdbc-mysql-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.validation.validationbuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.jem.workbench.JavaEMFNature 26 | org.eclipse.wst.common.modulecore.ModuleCoreNature 27 | org.eclipse.wst.common.project.facet.core.nature 28 | org.eclipse.jdt.core.javanature 29 | org.eclipse.wst.jsdt.core.jsNature 30 | 31 | 32 | -------------------------------------------------------------------------------- /jsp-jdbc-mysql-example/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /jsp-jdbc-mysql-example/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /jsp-jdbc-mysql-example/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /jsp-jdbc-mysql-example/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /jsp-jdbc-mysql-example/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /jsp-jdbc-mysql-example/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /jsp-jdbc-mysql-example/WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /jsp-jdbc-mysql-example/WebContent/WEB-INF/lib/mysql-connector-java-8.0.13.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/jsp-jdbc-mysql-example/WebContent/WEB-INF/lib/mysql-connector-java-8.0.13.jar -------------------------------------------------------------------------------- /jsp-jdbc-mysql-example/WebContent/employeedetails.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | <%@page import="net.javaguides.jsp.jdbc.database.*"%> 4 | 5 | 6 | 7 | 8 | Insert title here 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | <% 18 | EmployeeDao employeeDao = new EmployeeDao(); 19 | int status = employeeDao.registerEmployee(employee); 20 | if (status > 0) { 21 | out.print("You are successfully registered"); 22 | } 23 | %> 24 | 25 | -------------------------------------------------------------------------------- /jsp-jdbc-mysql-example/WebContent/employeeregister.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |

Employee Register Form

11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
First Name
Last Name
UserName
Password
Address
Contact No
37 |
38 | 39 | -------------------------------------------------------------------------------- /jsp-jdbc-mysql-example/build/classes/net/javaguides/jsp/jdbc/bean/Employee.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/jsp-jdbc-mysql-example/build/classes/net/javaguides/jsp/jdbc/bean/Employee.class -------------------------------------------------------------------------------- /jsp-jdbc-mysql-example/build/classes/net/javaguides/jsp/jdbc/database/EmployeeDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/jsp-jdbc-mysql-example/build/classes/net/javaguides/jsp/jdbc/database/EmployeeDao.class -------------------------------------------------------------------------------- /jsp-jdbc-mysql-example/src/net/javaguides/jsp/jdbc/bean/Employee.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.jsp.jdbc.bean; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * JavaBean class used in jsp action tags. 7 | * @author Ramesh Fadatare 8 | */ 9 | public class Employee implements Serializable { 10 | /** 11 | * 12 | */ 13 | private static final long serialVersionUID = 1L; 14 | private String firstName; 15 | private String lastName; 16 | private String username; 17 | private String password; 18 | private String address; 19 | private String contact; 20 | public String getFirstName() { 21 | return firstName; 22 | } 23 | public void setFirstName(String firstName) { 24 | this.firstName = firstName; 25 | } 26 | public String getLastName() { 27 | return lastName; 28 | } 29 | public void setLastName(String lastName) { 30 | this.lastName = lastName; 31 | } 32 | public String getUsername() { 33 | return username; 34 | } 35 | public void setUsername(String username) { 36 | this.username = username; 37 | } 38 | public String getPassword() { 39 | return password; 40 | } 41 | public void setPassword(String password) { 42 | this.password = password; 43 | } 44 | public String getAddress() { 45 | return address; 46 | } 47 | public void setAddress(String address) { 48 | this.address = address; 49 | } 50 | public String getContact() { 51 | return contact; 52 | } 53 | public void setContact(String contact) { 54 | this.contact = contact; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /jsp-jdbc-mysql-example/src/net/javaguides/jsp/jdbc/database/EmployeeDao.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.jsp.jdbc.database; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.PreparedStatement; 6 | import java.sql.SQLException; 7 | 8 | import net.javaguides.jsp.jdbc.bean.Employee; 9 | 10 | public class EmployeeDao { 11 | 12 | public int registerEmployee(Employee employee) throws ClassNotFoundException { 13 | String INSERT_USERS_SQL = "INSERT INTO employee" 14 | + " (id, first_name, last_name, username, password, address, contact) VALUES " 15 | + " (?, ?, ?, ?, ?,?,?);"; 16 | 17 | int result = 0; 18 | 19 | Class.forName("com.mysql.jdbc.Driver"); 20 | 21 | try (Connection connection = DriverManager 22 | .getConnection("jdbc:mysql://localhost:3306/mysql_database?useSSL=false", "root", "root"); 23 | 24 | // Step 2:Create a statement using connection object 25 | PreparedStatement preparedStatement = connection.prepareStatement(INSERT_USERS_SQL)) { 26 | preparedStatement.setInt(1, 1); 27 | preparedStatement.setString(2, employee.getFirstName()); 28 | preparedStatement.setString(3, employee.getLastName()); 29 | preparedStatement.setString(4, employee.getUsername()); 30 | preparedStatement.setString(5, employee.getPassword()); 31 | preparedStatement.setString(6, employee.getAddress()); 32 | preparedStatement.setString(7, employee.getContact()); 33 | 34 | System.out.println(preparedStatement); 35 | // Step 3: Execute the query or update query 36 | result = preparedStatement.executeUpdate(); 37 | 38 | } catch (SQLException e) { 39 | // process sql exception 40 | printSQLException(e); 41 | } 42 | return result; 43 | } 44 | 45 | private void printSQLException(SQLException ex) { 46 | for (Throwable e: ex) { 47 | if (e instanceof SQLException) { 48 | e.printStackTrace(System.err); 49 | System.err.println("SQLState: " + ((SQLException) e).getSQLState()); 50 | System.err.println("Error Code: " + ((SQLException) e).getErrorCode()); 51 | System.err.println("Message: " + e.getMessage()); 52 | Throwable t = ex.getCause(); 53 | while (t != null) { 54 | System.out.println("Cause: " + t); 55 | t = t.getCause(); 56 | } 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /jsp-tutorial/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /jsp-tutorial/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jsp-tutorial 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.validation.validationbuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.jem.workbench.JavaEMFNature 26 | org.eclipse.wst.common.modulecore.ModuleCoreNature 27 | org.eclipse.wst.common.project.facet.core.nature 28 | org.eclipse.jdt.core.javanature 29 | org.eclipse.wst.jsdt.core.jsNature 30 | 31 | 32 | -------------------------------------------------------------------------------- /jsp-tutorial/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /jsp-tutorial/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /jsp-tutorial/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /jsp-tutorial/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /jsp-tutorial/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /jsp-tutorial/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/WEB-INF/lib/mysql-connector-java-8.0.13.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/jsp-tutorial/WebContent/WEB-INF/lib/mysql-connector-java-8.0.13.jar -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/WEB-INF/message.tld: -------------------------------------------------------------------------------- 1 | 2 | 1.0 3 | 2.0 4 | My Custom Tag 5 | 6 | CustomTag 7 | net.javaguides.jsp.tutorial.jstl.CustomTag 8 | empty 9 | 10 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/callingjavaclass.jsp: -------------------------------------------------------------------------------- 1 | <%@page import="net.javaguides.jsp.tutorial.Calculator"%> 2 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 3 | pageEncoding="ISO-8859-1"%> 4 | 5 | 6 | 7 | 8 | Insert title here 9 | 10 | 11 | 12 | <% Calculator calculator = new Calculator(); %> 13 | 14 | Addition of 20 + 10 = 15 | <%= calculator.addition(20, 10) %> 16 | 17 | 18 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/converter.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | <%@ page session="false"%> 5 | <%@ page import="java.io.*,java.text.*,java.util.*"%> 6 | 7 | 8 | 9 | 10 | 11 | >Fuel Efficiency Conversion Chart 12 | <%!private static final DecimalFormat FMT = new DecimalFormat("#0.00");%> 13 | 14 | 15 | <%-- Prints a conversion table of miles per gallon to kilometers per liter --%> 16 | 17 |

Fuel Efficiency Conversion Chart

18 | 19 | 20 | 21 | 22 | 23 | <% 24 | for (double kpl = 5; kpl <= 20; kpl += 1.0) { 25 | double mpg = kpl * 2.352146; 26 | %> 27 | 28 | 29 | 30 | 31 | <% 32 | } 33 | %> 34 |
Kilometers per LiterMiles per Gallon
<%=FMT.format(kpl)%><%=FMT.format(mpg)%>
35 | 36 | 37 | 38 | SELECT * 39 | FROM FD_GROUP 40 | WHERE FdGp_Desc LIKE '%F%' 41 | ORDER BY FdGp_Cd 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
Food Group CodeDescription
55 |
56 | 57 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/database/employeedetails.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | <%@page import="net.javaguides.jsp.tutorial.database.*"%> 4 | 5 | 6 | 7 | 8 | Insert title here 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | <% 18 | EmployeeDao employeeDao = new EmployeeDao(); 19 | int status = employeeDao.registerEmployee(employee); 20 | if (status > 0) { 21 | out.print("You are successfully registered"); 22 | } 23 | %> 24 | 25 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/database/employeeregister.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |

Employee Register Form

11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
First Name
Last Name
UserName
Password
Address
Contact No
37 |
38 | 39 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/declarationtag.jsp: -------------------------------------------------------------------------------- 1 | <%@page import="java.time.LocalDate"%> 2 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 3 | pageEncoding="ISO-8859-1"%> 4 | 5 | 6 | 7 | 8 | Insert title here 9 | 10 | 11 |

Using variables in declaration tag

12 | <%!String firstName = "Ramesh";%> 13 | <%!String lastName = "Fadatare";%> 14 | <%!int age = 28;%> 15 | <%!LocalDate dob = LocalDate.of(1991, 03, 24);%> 16 | 17 |
First Name: 18 | <%=firstName%> 19 |
Last Name: 20 | <%=lastName%> 21 | 22 |
Age: 23 | <%=age%> 24 | 25 |
Date of Birth: 26 | <%=dob%> 27 | 28 |

Using methods in declaration tag

29 | <%! 30 | String getFirstName(){ 31 | return "Ramesh"; 32 | } 33 | %> 34 | 35 | <%! 36 | String getLastName(){ 37 | return "Fadatare"; 38 | } 39 | %> 40 | 41 | 42 |
First Name: 43 | <%= getFirstName() %> 44 | 45 |
Last Name: 46 | <%= getLastName() %> 47 | 48 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/expressiontag.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 | 11 | Converting a string to uppercase: 12 | <%=new String("Hello World").toUpperCase()%> 13 | 14 |
15 |
16 | Port of Server : 17 | <%= request.getLocalPort() %> 18 | 19 |
20 |
21 | Context path : 22 | <%= application.getContextPath() %> 23 | 24 |
25 |
25 multiplied by 4 equals 26 | <%=25 * 4%> 27 | 28 |
29 |
Is 75 less than 69? 30 | <%=75 < 69%> 31 | 32 | 33 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/form/student-checkbox-form.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Student Registration Form 4 | 5 | 6 | 7 |
8 | 9 | First name: 10 | 11 |

12 | 13 | Last name: 14 | 15 |

16 | 17 | Java 18 | 19 | C# 20 | 21 | PHP 22 | 23 | Ruby 24 | 25 |

26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/form/student-checkbox-response.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | Student Confirmation Title 4 | 5 | 6 | 7 |
    8 |
  • First Name: 9 | <%= request.getParameter("firstName") %> 10 |

  • 11 |
  • Last Name: 12 | <%= request.getParameter("lastName") %> 13 |

  • 14 |
15 | 16 | Favorite Programming Languages:
17 | 18 | 19 |
    20 | <% 21 | String[] langs = request.getParameterValues("favoriteLanguage"); 22 | 23 | for (String tempLang : langs) { 24 | out.println("
  • " + tempLang + "
  • "); 25 | } 26 | %> 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/form/student-dropdown-form.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Student Registration Form 4 | 5 | 6 | 7 |
8 | 9 | First name: 10 | 11 |

12 | 13 | Last name: 14 | 15 |

16 | 17 | 26 | 27 |

28 | 29 | 30 | 31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/form/student-dropdown-response.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Student Confirmation Title 5 | 6 | 7 | 8 |
    9 |
  • First Name: 10 | <%= request.getParameter("firstName") %> 11 |

  • 12 |
  • Last Name: 13 | <%= request.getParameter("lastName") %> 14 |

  • 15 |
16 |
17 |
The student's country: ${param.country} 18 | 19 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/form/student-form.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Student Registration Form 4 | 5 | 6 | 7 |
8 | 9 | First name: 10 | 11 |

12 | 13 | Last name: 14 | 15 |

16 | 17 | 18 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/form/student-radio-form.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Student Registration Form 4 | 5 | 6 | 7 |
8 | 9 | First name: 10 | 11 |

12 | 13 | Last name: 14 | 15 |

16 | 17 | Favorite Programming Language:
18 | 19 | Java 20 | 21 | C# 22 | 23 | PHP 24 | 25 | Ruby 26 | 27 |

28 | 29 | 30 | 31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/form/student-radio-response.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | Student Confirmation Title 4 | 5 | 6 | 7 |
    8 |
  • First Name: 9 | <%= request.getParameter("firstName") %> 10 |

  • 11 |
  • Last Name: 12 | <%= request.getParameter("lastName") %> 13 |

  • 14 |
15 | 16 |

17 | 18 | The student's favorite programming language: 19 | <%= request.getParameter("favoriteLanguage") %> 20 | 21 | 22 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/form/student-response.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | Student Confirmation Title 4 | 5 |
    6 |
  • First Name: 7 | <%= request.getParameter("firstName") %> 8 |

  • 9 |
  • Last Name: 10 | <%= request.getParameter("lastName") %> 11 |

  • 12 |
13 | 14 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/helloworld.jsp: -------------------------------------------------------------------------------- 1 | <%@page import="java.time.LocalTime"%> 2 | <%@page import="java.time.LocalDate"%> 3 | 4 | 5 | 6 | 7 |

Hello World of Java!

8 | 9 | Date and Time on Server : 10 | <%=LocalDate.now()%> 11 | <%=LocalTime.now()%> 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/implicitobjects.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1" isErrorPage="true" %> 3 | 4 | 5 | 6 | 7 | 8 | Insert title here 9 | 10 | 11 | <%= request %> 12 | 13 | <%= response %> 14 | 15 | <%= pageContext %> 16 | 17 | <%= session %> 18 | 19 | <%= application %> 20 | 21 | <%= out %> 22 | 23 | <%= config %> 24 | 25 | <%= page %> 26 | 27 | <%= exception %> 28 | 29 | 30 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/include/footer.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |
11 |

Footer Section

12 |
13 | 14 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/include/header.jsp: -------------------------------------------------------------------------------- 1 | <%@page import="java.time.LocalDate"%> 2 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 3 | pageEncoding="ISO-8859-1"%> 4 | 5 | 6 | 7 | 8 | Insert title here 9 | 10 | 11 |
12 |

Header Section

13 | Today is: <%= LocalDate.now() %> 14 |
15 | 16 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 | <%@ include file="include/header.jsp" %> 11 | 12 |

13 | Inside Body Section 14 |

15 | 16 | <%@ include file="include/footer.jsp" %> 17 | 18 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/jstl/customtag.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | <%@ taglib prefix="myprefix" uri="../WEB-INF/message.tld"%> 5 | 6 | 7 | 8 | 9 | JSP Custom Tag Example 10 | 11 | 12 |

Basic Example of a Custom Tag

13 | 14 | 15 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/redirect/page1.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |

Inside Page 1

11 | 12 | <% 13 | 14 | String redirectURL = "http://localhost:8080/jsp-tutorial/redirect/page2.jsp"; 15 | 16 | response.sendRedirect(redirectURL); 17 | 18 | %> 19 | 20 | 21 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/redirect/page2.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |

Inside page 2

11 | 12 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/request.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/scriptlets.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |

ASCII Table

11 | 12 | <% 13 | StringBuffer sb = new StringBuffer(); 14 | sb.append(""); 15 | sb.append(""); 16 | for (int col = 0; col < 16; col++) { 17 | sb.append(""); 20 | } 21 | sb.append(""); 22 | for (int row = 0; row < 16; row++) { 23 | sb.append(""); 24 | sb.append(""); 27 | for (int col = 0; col < 16; col++) { 28 | char c = (char) (row * 16 + col); 29 | sb.append(""); 32 | } 33 | sb.append(""); 34 | } 35 | out.println(sb); 36 | %> 37 |
 "); 18 | sb.append(Integer.toHexString(col)); 19 | sb.append("
"); 25 | sb.append(Integer.toHexString(row)); 26 | sb.append(""); 30 | sb.append(c); 31 | sb.append("
38 | 39 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/student.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | JSP Actions Example 8 | 9 | 10 | 11 |

Student Registration Page

12 |
13 | First Name: 14 |

15 | 16 | Last Name: 17 |

18 | 19 | Email ID: 20 |

21 | 22 | Password:
23 | 24 |
25 | 26 |
27 | 28 | -------------------------------------------------------------------------------- /jsp-tutorial/WebContent/studentdetails.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 | 11 | 12 | 13 |

Student Registered with Following Details

14 | First Name:

15 | Last Name:

16 | Email ID:

17 | Password: 18 | 19 | -------------------------------------------------------------------------------- /jsp-tutorial/build/classes/net/javaguides/jsp/tutorial/Calculator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/jsp-tutorial/build/classes/net/javaguides/jsp/tutorial/Calculator.class -------------------------------------------------------------------------------- /jsp-tutorial/build/classes/net/javaguides/jsp/tutorial/Student.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/jsp-tutorial/build/classes/net/javaguides/jsp/tutorial/Student.class -------------------------------------------------------------------------------- /jsp-tutorial/build/classes/net/javaguides/jsp/tutorial/database/Employee.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/jsp-tutorial/build/classes/net/javaguides/jsp/tutorial/database/Employee.class -------------------------------------------------------------------------------- /jsp-tutorial/build/classes/net/javaguides/jsp/tutorial/database/EmployeeDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/jsp-tutorial/build/classes/net/javaguides/jsp/tutorial/database/EmployeeDao.class -------------------------------------------------------------------------------- /jsp-tutorial/build/classes/net/javaguides/jsp/tutorial/jstl/CustomTag.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/jsp-tutorial/build/classes/net/javaguides/jsp/tutorial/jstl/CustomTag.class -------------------------------------------------------------------------------- /jsp-tutorial/src/net/javaguides/jsp/tutorial/Calculator.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.jsp.tutorial; 2 | 3 | public class Calculator { 4 | public int addition(int num1, int num2) { 5 | return (num1 + num2); 6 | } 7 | 8 | public int substraction(int num1, int num2) { 9 | return (num1 - num2); 10 | } 11 | 12 | public int multiplication(int num1, int num2) { 13 | return (num1 * num2); 14 | } 15 | 16 | public int division(int num1, int num2) { 17 | return (num1 / num2); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jsp-tutorial/src/net/javaguides/jsp/tutorial/Student.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.jsp.tutorial; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Student implements Serializable{ 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private String firstName; 10 | private String lastName; 11 | private String emailId; 12 | private String password; 13 | public String getFirstName() { 14 | return firstName; 15 | } 16 | public void setFirstName(String firstName) { 17 | this.firstName = firstName; 18 | } 19 | public String getLastName() { 20 | return lastName; 21 | } 22 | public void setLastName(String lastName) { 23 | this.lastName = lastName; 24 | } 25 | public String getEmailId() { 26 | return emailId; 27 | } 28 | public void setEmailId(String emailId) { 29 | this.emailId = emailId; 30 | } 31 | public String getPassword() { 32 | return password; 33 | } 34 | public void setPassword(String password) { 35 | this.password = password; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /jsp-tutorial/src/net/javaguides/jsp/tutorial/database/Employee.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.jsp.tutorial.database; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Employee implements Serializable { 6 | private String firstName; 7 | private String lastName; 8 | private String username; 9 | private String password; 10 | private String address; 11 | private String contact; 12 | public String getFirstName() { 13 | return firstName; 14 | } 15 | public void setFirstName(String firstName) { 16 | this.firstName = firstName; 17 | } 18 | public String getLastName() { 19 | return lastName; 20 | } 21 | public void setLastName(String lastName) { 22 | this.lastName = lastName; 23 | } 24 | public String getUsername() { 25 | return username; 26 | } 27 | public void setUsername(String username) { 28 | this.username = username; 29 | } 30 | public String getPassword() { 31 | return password; 32 | } 33 | public void setPassword(String password) { 34 | this.password = password; 35 | } 36 | public String getAddress() { 37 | return address; 38 | } 39 | public void setAddress(String address) { 40 | this.address = address; 41 | } 42 | public String getContact() { 43 | return contact; 44 | } 45 | public void setContact(String contact) { 46 | this.contact = contact; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /jsp-tutorial/src/net/javaguides/jsp/tutorial/database/EmployeeDao.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.jsp.tutorial.database; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.PreparedStatement; 6 | import java.sql.SQLException; 7 | 8 | public class EmployeeDao { 9 | 10 | public int registerEmployee(Employee employee) throws ClassNotFoundException { 11 | String INSERT_USERS_SQL = "INSERT INTO employee" 12 | + " (id, first_name, last_name, username, password, address, contact) VALUES " 13 | + " (?, ?, ?, ?, ?,?,?);"; 14 | 15 | int result = 0; 16 | 17 | Class.forName("com.mysql.jdbc.Driver"); 18 | 19 | try (Connection connection = DriverManager 20 | .getConnection("jdbc:mysql://localhost:3306/mysql_database?useSSL=false", "root", "root"); 21 | 22 | // Step 2:Create a statement using connection object 23 | PreparedStatement preparedStatement = connection.prepareStatement(INSERT_USERS_SQL)) { 24 | preparedStatement.setInt(1, 1); 25 | preparedStatement.setString(2, employee.getFirstName()); 26 | preparedStatement.setString(3, employee.getLastName()); 27 | preparedStatement.setString(4, employee.getUsername()); 28 | preparedStatement.setString(5, employee.getPassword()); 29 | preparedStatement.setString(6, employee.getAddress()); 30 | preparedStatement.setString(7, employee.getContact()); 31 | 32 | System.out.println(preparedStatement); 33 | // Step 3: Execute the query or update query 34 | result = preparedStatement.executeUpdate(); 35 | 36 | } catch (SQLException e) { 37 | // process sql exception 38 | printSQLException(e); 39 | } 40 | return result; 41 | } 42 | 43 | private void printSQLException(SQLException ex) { 44 | for (Throwable e: ex) { 45 | if (e instanceof SQLException) { 46 | e.printStackTrace(System.err); 47 | System.err.println("SQLState: " + ((SQLException) e).getSQLState()); 48 | System.err.println("Error Code: " + ((SQLException) e).getErrorCode()); 49 | System.err.println("Message: " + e.getMessage()); 50 | Throwable t = ex.getCause(); 51 | while (t != null) { 52 | System.out.println("Cause: " + t); 53 | t = t.getCause(); 54 | } 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /jsp-tutorial/src/net/javaguides/jsp/tutorial/jstl/CustomTag.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.jsp.tutorial.jstl; 2 | 3 | import java.io.IOException; 4 | import java.time.LocalDate; 5 | import java.time.LocalTime; 6 | import java.time.Month; 7 | 8 | import javax.servlet.jsp.JspWriter; 9 | import javax.servlet.jsp.tagext.SimpleTagSupport; 10 | 11 | /** 12 | * Simple JSP Custom tag handler 13 | * @author Ramesh Fadatare 14 | * 15 | */ 16 | public class CustomTag extends SimpleTagSupport { 17 | public void doTag() throws IOException { 18 | /* 19 | * This is just to display a message, when we will use our custom tag. This 20 | * message would be displayed 21 | */ 22 | JspWriter out = getJspContext().getOut(); 23 | out.println("Current Date :: " + LocalDate.now()); 24 | out.println("
"); 25 | out.println("Current Time :: " + LocalTime.now()); 26 | out.println("
"); 27 | out.println("Print Months"); 28 | for(Month month : Month.values()) { 29 | out.println(month.name()); 30 | out.println("
"); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /jstl-tutorial/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /jstl-tutorial/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jstl-tutorial 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.validation.validationbuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.jem.workbench.JavaEMFNature 26 | org.eclipse.wst.common.modulecore.ModuleCoreNature 27 | org.eclipse.wst.common.project.facet.core.nature 28 | org.eclipse.jdt.core.javanature 29 | org.eclipse.wst.jsdt.core.jsNature 30 | 31 | 32 | -------------------------------------------------------------------------------- /jstl-tutorial/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /jstl-tutorial/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /jstl-tutorial/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /jstl-tutorial/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /jstl-tutorial/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /jstl-tutorial/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /jstl-tutorial/WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /jstl-tutorial/WebContent/WEB-INF/lib/javax.servlet.jsp.jstl-1.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/jstl-tutorial/WebContent/WEB-INF/lib/javax.servlet.jsp.jstl-1.2.1.jar -------------------------------------------------------------------------------- /jstl-tutorial/WebContent/WEB-INF/lib/javax.servlet.jsp.jstl-api-1.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/jstl-tutorial/WebContent/WEB-INF/lib/javax.servlet.jsp.jstl-api-1.2.1.jar -------------------------------------------------------------------------------- /jstl-tutorial/WebContent/choose-student-test.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | 3 | <%@ page import="java.util.*,net.javaguides.jstl.Student" %> 4 | 5 | <% 6 | // just create some sample data ... normally provided by MVC 7 | List data = new ArrayList<>(); 8 | 9 | data.add(new Student("Ramesh", "Fadatare", false)); 10 | data.add(new Student("John", "Cena", false)); 11 | data.add(new Student("Tom", "Cruise", false)); 12 | data.add(new Student("Tony", "Stark", false)); 13 | data.add(new Student("Prakash", "Jadhav", true)); 14 | pageContext.setAttribute("myStudents", data); 15 | %> 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 47 | 48 | 49 | 50 | 51 |
First NameLast NameGold Customer
${tempStudent.firstName}${tempStudent.lastName} 34 | 35 | 36 | 37 | Special Discount 38 | 39 | 40 | 41 | no soup for you! 42 | 43 | 44 | 45 | 46 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /jstl-tutorial/WebContent/foreach-simple-test.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | 3 | <% 4 | // just create some sample data ... normally provided by MVC 5 | String[] cities = {"Mumbai", "Singapore", "Philadelphia"}; 6 | 7 | pageContext.setAttribute("myCities", cities); 8 | %> 9 | 10 | 11 | 12 | 13 | 14 | ${tempCity}
15 | 16 |
17 | 18 | -------------------------------------------------------------------------------- /jstl-tutorial/WebContent/foreach-student-test.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 2 | 3 | <%@ page import="java.util.*,net.javaguides.jstl.Student"%> 4 | 5 | <% 6 | // just create some sample data ... normally provided by MVC 7 | List data = new ArrayList<>(); 8 | 9 | data.add(new Student("Ramesh", "Fadatare", false)); 10 | data.add(new Student("John", "Cena", false)); 11 | data.add(new Student("Tom", "Cruise", false)); 12 | data.add(new Student("Tony", "Stark", false)); 13 | data.add(new Student("Prakash", "Jadhav", true)); 14 | pageContext.setAttribute("myStudents", data); 15 | %> 16 | 17 | 18 | 19 | 20 | 21 |

List of students

22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
First NameLast NameGold Customer
${tempStudent.firstName}${tempStudent.lastName}${tempStudent.goldCustomer}
41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /jstl-tutorial/WebContent/if-student-test.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | 3 | <%@ page import="java.util.*,net.javaguides.jstl.Student" %> 4 | 5 | <% 6 | // just create some sample data ... normally provided by MVC 7 | List data = new ArrayList<>(); 8 | 9 | data.add(new Student("Ramesh", "Fadatare", false)); 10 | data.add(new Student("John", "Cena", false)); 11 | data.add(new Student("Tom", "Cruise", false)); 12 | data.add(new Student("Tony", "Stark", false)); 13 | data.add(new Student("Prakash", "Jadhav", true)); 14 | pageContext.setAttribute("myStudents", data); 15 | %> 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 43 | 44 | 45 | 46 | 47 |
First NameLast NameGold Customer
${tempStudent.firstName}${tempStudent.lastName} 34 | 35 | Special Discount 36 | 37 | 38 | 39 | - 40 | 41 | 42 |
48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /jstl-tutorial/WebContent/jstl-functions-examples.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 5 | <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> 6 | 7 | 8 | 9 | 10 | 11 | Insert title here 12 | 13 | 14 | 15 |

JSTL fn:contains() function example

16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 |

JSTL fn:containsIgnoreCase() function example

25 | 26 | 27 | 28 | 29 | 30 | 31 |
32 | 33 |

JSTL fn:indexOf() function example

34 | 35 | 36 |

Index of "Guides" in "Java Guides" : ${fn:indexOf(str1, str2)}

37 |
38 | 39 |

JSTL fn:join() function example

40 | <% 41 | String arr[] = { "Java", "Programming", "Language" }; 42 | session.setAttribute("names", arr); 43 | %> 44 | ${fn:join(names, " & ")} 45 | 46 |
47 |

JSTL fn:split() function example

48 | 49 | 50 | 51 | arrayofmsg[${i}]: ${arrayofmsg[i]}
52 |
53 | 54 |
55 |

JSTL fn:length() function example

56 | 57 | Length of str is: ${fn:length(str)} 58 |
59 | 60 |
61 |

JSTL fn:trim() function example

62 | 63 | Trim of " Java Guides " is: ${fn:trim(str)} 64 |
65 | 66 |
67 |

JSTL fn:startsWith() function example

68 | 69 | Java Guides starts with Java : ${fn:startsWith(str, 'Java')} 70 |
71 | 72 |
73 |

JSTL fn:endsWith() function example

74 | 75 | Java Guides ends with Guides : ${fn:endsWith(str, 'Guides')} 76 |
77 | 78 |
79 |

JSTL fn:substring() function example

80 | 81 | ${fn:substring(msg, 5, 10)} 82 |
83 | 84 |
85 |

JSTL fn:substringAfter() function example

86 | 87 | ${fn:substringAfter(str, "Gu")} 88 |
89 | 90 |
91 |

JSTL fn:substringBefore() function example

92 | 93 | ${fn:substringBefore(str, "Gu")} 94 |
95 | 96 | 97 |
98 |

JSTL fn:toUpperCase() function example

99 | 100 | Upper case of "java guides" is: ${fn:toUpperCase(str)} 101 |
102 | 103 |
104 |

JSTL fn:toLowerCase() function example

105 | 106 | Lower case of "JAVA GUIDES" is: ${fn:toLowerCase(str)} 107 |
108 | 109 |
110 | 111 | 112 | ${fn:replace(author, "Ramesh", "Umesh")} 113 | ${fn:replace(randomstring, "abc", "hello")} 114 | 115 | 116 | -------------------------------------------------------------------------------- /jstl-tutorial/WebContent/test.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Time on the server is ${stuff} 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /jstl-tutorial/build/classes/net/javaguides/jstl/Student.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/jstl-tutorial/build/classes/net/javaguides/jstl/Student.class -------------------------------------------------------------------------------- /jstl-tutorial/src/net/javaguides/jstl/Student.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.jstl; 2 | 3 | public class Student { 4 | 5 | private String firstName; 6 | private String lastName; 7 | private boolean goldCustomer; 8 | 9 | public Student(String firstName, String lastName, boolean goldCustomer) { 10 | super(); 11 | this.firstName = firstName; 12 | this.lastName = lastName; 13 | this.goldCustomer = goldCustomer; 14 | } 15 | 16 | public String getFirstName() { 17 | return firstName; 18 | } 19 | 20 | public void setFirstName(String firstName) { 21 | this.firstName = firstName; 22 | } 23 | 24 | public String getLastName() { 25 | return lastName; 26 | } 27 | 28 | public void setLastName(String lastName) { 29 | this.lastName = lastName; 30 | } 31 | 32 | public boolean isGoldCustomer() { 33 | return goldCustomer; 34 | } 35 | 36 | public void setGoldCustomer(boolean goldCustomer) { 37 | this.goldCustomer = goldCustomer; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /login-jsp-jdbc-example/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /login-jsp-jdbc-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | login-jsp-jdbc-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.validation.validationbuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.jem.workbench.JavaEMFNature 26 | org.eclipse.wst.common.modulecore.ModuleCoreNature 27 | org.eclipse.wst.common.project.facet.core.nature 28 | org.eclipse.jdt.core.javanature 29 | org.eclipse.wst.jsdt.core.jsNature 30 | 31 | 32 | -------------------------------------------------------------------------------- /login-jsp-jdbc-example/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /login-jsp-jdbc-example/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /login-jsp-jdbc-example/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /login-jsp-jdbc-example/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /login-jsp-jdbc-example/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /login-jsp-jdbc-example/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /login-jsp-jdbc-example/WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /login-jsp-jdbc-example/WebContent/WEB-INF/lib/mysql-connector-java-8.0.13.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/login-jsp-jdbc-example/WebContent/WEB-INF/lib/mysql-connector-java-8.0.13.jar -------------------------------------------------------------------------------- /login-jsp-jdbc-example/WebContent/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |

Employee Login Form

11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
UserName
Password
23 | 24 |
25 | 26 | -------------------------------------------------------------------------------- /login-jsp-jdbc-example/WebContent/loginsuccess.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | <%@page import="net.javaguides.login.database.*"%> 4 | 5 | 6 | 7 | 8 | Insert title here 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | <% 17 | LoginDao loginDao = new LoginDao(); 18 | boolean status = loginDao.validate(login); 19 | if (status) { 20 | out.print("

You have logined successfully

"); 21 | } 22 | %> 23 | 24 | -------------------------------------------------------------------------------- /login-jsp-jdbc-example/build/classes/net/javaguides/login/bean/LoginBean.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/login-jsp-jdbc-example/build/classes/net/javaguides/login/bean/LoginBean.class -------------------------------------------------------------------------------- /login-jsp-jdbc-example/build/classes/net/javaguides/login/database/LoginDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/login-jsp-jdbc-example/build/classes/net/javaguides/login/database/LoginDao.class -------------------------------------------------------------------------------- /login-jsp-jdbc-example/src/net/javaguides/login/bean/LoginBean.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.login.bean; 2 | 3 | import java.io.Serializable; 4 | 5 | public class LoginBean implements Serializable { 6 | /** 7 | * 8 | */ 9 | private static final long serialVersionUID = 1L; 10 | private String username; 11 | private String password; 12 | 13 | public String getUsername() { 14 | return username; 15 | } 16 | 17 | public void setUsername(String username) { 18 | this.username = username; 19 | } 20 | 21 | public String getPassword() { 22 | return password; 23 | } 24 | 25 | public void setPassword(String password) { 26 | this.password = password; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /login-jsp-jdbc-example/src/net/javaguides/login/database/LoginDao.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.login.database; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.PreparedStatement; 6 | import java.sql.ResultSet; 7 | import java.sql.SQLException; 8 | 9 | import net.javaguides.login.bean.LoginBean; 10 | 11 | public class LoginDao { 12 | 13 | public boolean validate(LoginBean loginBean) throws ClassNotFoundException { 14 | boolean status = false; 15 | 16 | Class.forName("com.mysql.jdbc.Driver"); 17 | 18 | try (Connection connection = DriverManager 19 | .getConnection("jdbc:mysql://localhost:3306/mysql_database?useSSL=false", "root", "root"); 20 | 21 | // Step 2:Create a statement using connection object 22 | PreparedStatement preparedStatement = connection 23 | .prepareStatement("select * from login where username = ? and password = ? ")) { 24 | preparedStatement.setString(1, loginBean.getUsername()); 25 | preparedStatement.setString(2, loginBean.getPassword()); 26 | 27 | System.out.println(preparedStatement); 28 | ResultSet rs = preparedStatement.executeQuery(); 29 | status = rs.next(); 30 | 31 | } catch (SQLException e) { 32 | // process sql exception 33 | printSQLException(e); 34 | } 35 | return status; 36 | } 37 | 38 | private void printSQLException(SQLException ex) { 39 | for (Throwable e : ex) { 40 | if (e instanceof SQLException) { 41 | e.printStackTrace(System.err); 42 | System.err.println("SQLState: " + ((SQLException) e).getSQLState()); 43 | System.err.println("Error Code: " + ((SQLException) e).getErrorCode()); 44 | System.err.println("Message: " + e.getMessage()); 45 | Throwable t = ex.getCause(); 46 | while (t != null) { 47 | System.out.println("Cause: " + t); 48 | t = t.getCause(); 49 | } 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /registration-jsp-jdbc-example/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /registration-jsp-jdbc-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | registration-jsp-jdbc-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.validation.validationbuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.jem.workbench.JavaEMFNature 26 | org.eclipse.wst.common.modulecore.ModuleCoreNature 27 | org.eclipse.wst.common.project.facet.core.nature 28 | org.eclipse.jdt.core.javanature 29 | org.eclipse.wst.jsdt.core.jsNature 30 | 31 | 32 | -------------------------------------------------------------------------------- /registration-jsp-jdbc-example/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /registration-jsp-jdbc-example/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /registration-jsp-jdbc-example/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /registration-jsp-jdbc-example/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /registration-jsp-jdbc-example/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /registration-jsp-jdbc-example/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /registration-jsp-jdbc-example/WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /registration-jsp-jdbc-example/WebContent/WEB-INF/lib/mysql-connector-java-8.0.13.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/registration-jsp-jdbc-example/WebContent/WEB-INF/lib/mysql-connector-java-8.0.13.jar -------------------------------------------------------------------------------- /registration-jsp-jdbc-example/WebContent/employeedetails.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | <%@page import="net.javaguides.jsp.jdbc.database.*"%> 4 | 5 | 6 | 7 | 8 | Insert title here 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | <% 18 | EmployeeDao employeeDao = new EmployeeDao(); 19 | int status = employeeDao.registerEmployee(employee); 20 | if (status > 0) { 21 | out.print("You are successfully registered"); 22 | } 23 | %> 24 | 25 | -------------------------------------------------------------------------------- /registration-jsp-jdbc-example/WebContent/employeeregister.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |

Employee Register Form

11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
First Name
Last Name
UserName
Password
Address
Contact No
37 |
38 | 39 | -------------------------------------------------------------------------------- /registration-jsp-jdbc-example/build/classes/net/javaguides/registration/bean/Employee.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/registration-jsp-jdbc-example/build/classes/net/javaguides/registration/bean/Employee.class -------------------------------------------------------------------------------- /registration-jsp-jdbc-example/build/classes/net/javaguides/registration/database/EmployeeDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/JSP-Tutorial/9bf61e40615b9d62a39ee05e334592df4a386735/registration-jsp-jdbc-example/build/classes/net/javaguides/registration/database/EmployeeDao.class -------------------------------------------------------------------------------- /registration-jsp-jdbc-example/src/net/javaguides/registration/bean/Employee.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.registration.bean; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Employee implements Serializable { 6 | /** 7 | * 8 | */ 9 | private static final long serialVersionUID = 1L; 10 | private String firstName; 11 | private String lastName; 12 | private String username; 13 | private String password; 14 | private String address; 15 | private String contact; 16 | public String getFirstName() { 17 | return firstName; 18 | } 19 | public void setFirstName(String firstName) { 20 | this.firstName = firstName; 21 | } 22 | public String getLastName() { 23 | return lastName; 24 | } 25 | public void setLastName(String lastName) { 26 | this.lastName = lastName; 27 | } 28 | public String getUsername() { 29 | return username; 30 | } 31 | public void setUsername(String username) { 32 | this.username = username; 33 | } 34 | public String getPassword() { 35 | return password; 36 | } 37 | public void setPassword(String password) { 38 | this.password = password; 39 | } 40 | public String getAddress() { 41 | return address; 42 | } 43 | public void setAddress(String address) { 44 | this.address = address; 45 | } 46 | public String getContact() { 47 | return contact; 48 | } 49 | public void setContact(String contact) { 50 | this.contact = contact; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /registration-jsp-jdbc-example/src/net/javaguides/registration/database/EmployeeDao.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.registration.database; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.PreparedStatement; 6 | import java.sql.SQLException; 7 | 8 | import net.javaguides.registration.bean.Employee; 9 | 10 | public class EmployeeDao { 11 | 12 | public int registerEmployee(Employee employee) throws ClassNotFoundException { 13 | String INSERT_USERS_SQL = "INSERT INTO employee" 14 | + " (id, first_name, last_name, username, password, address, contact) VALUES " 15 | + " (?, ?, ?, ?, ?,?,?);"; 16 | 17 | int result = 0; 18 | 19 | Class.forName("com.mysql.jdbc.Driver"); 20 | 21 | try (Connection connection = DriverManager 22 | .getConnection("jdbc:mysql://localhost:3306/mysql_database?useSSL=false", "root", "root"); 23 | 24 | // Step 2:Create a statement using connection object 25 | PreparedStatement preparedStatement = connection.prepareStatement(INSERT_USERS_SQL)) { 26 | preparedStatement.setInt(1, 1); 27 | preparedStatement.setString(2, employee.getFirstName()); 28 | preparedStatement.setString(3, employee.getLastName()); 29 | preparedStatement.setString(4, employee.getUsername()); 30 | preparedStatement.setString(5, employee.getPassword()); 31 | preparedStatement.setString(6, employee.getAddress()); 32 | preparedStatement.setString(7, employee.getContact()); 33 | 34 | System.out.println(preparedStatement); 35 | // Step 3: Execute the query or update query 36 | result = preparedStatement.executeUpdate(); 37 | 38 | } catch (SQLException e) { 39 | // process sql exception 40 | printSQLException(e); 41 | } 42 | return result; 43 | } 44 | 45 | private void printSQLException(SQLException ex) { 46 | for (Throwable e: ex) { 47 | if (e instanceof SQLException) { 48 | e.printStackTrace(System.err); 49 | System.err.println("SQLState: " + ((SQLException) e).getSQLState()); 50 | System.err.println("Error Code: " + ((SQLException) e).getErrorCode()); 51 | System.err.println("Message: " + e.getMessage()); 52 | Throwable t = ex.getCause(); 53 | while (t != null) { 54 | System.out.println("Cause: " + t); 55 | t = t.getCause(); 56 | } 57 | } 58 | } 59 | } 60 | } 61 | --------------------------------------------------------------------------------