Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //web.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="4.0" 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_4_0.xsd">
- <session-config>
- <session-timeout>
- 30
- </session-timeout>
- </session-config>
- <resource-ref>
- <res-ref-name>jdbc/ass1</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- <res-sharing-scope>Shareable</res-sharing-scope>
- </resource-ref>
- </web-app>
- //pom.xml
- <dependencies>
- <dependency>
- <groupId>com.mysql</groupId>
- <artifactId>mysql-connector-j</artifactId>
- <version>8.0.33</version>
- </dependency>
- </dependencies>
- //index.jsp
- <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
- <%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
- <sql:setDataSource dataSource="jdbc/ass1"/>
- <sql:query var="result">
- SELECT * FROM Student
- </sql:query>
- <c:forEach var="sql" items="${result.rowsByIndex}">
- <table border="2">
- <tr>
- <td>${sql[0]}</td>
- <td>${sql[1]}</td>
- <td>${sql[2]}</td>
- </tr>
- </table>
- </c:forEach>
- //registration.jsp
- <sql:setDataSource dataSource="jdbc/urvil"/>
- <c:if test="${not empty param.name and not empty param.age}">
- <!-- Insert Data into Database -->
- <sql:update var="result">
- INSERT INTO student(id, name, age)
- VALUES
- (null, '${param.name}', '${param.age}')
- </sql:update>
- <!-- Redirect to newjsp.jsp if the registration is successful -->
- <c:if test="${result != null}">
- <p>Registration successful! Redirecting...</p>
- <c:redirect url="newjsp.jsp"/>
- </c:if>
- </c:if>
- <form action="registration.jsp" method="post">
- <label for="name">Name:</label><br>
- <input type="text" id="name" name="name" required><br><br>
- <label for="age">Age:</label><br>
- <input type="number" id="age" name="age" required><br><br>
- <input type="submit" value="Register">
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement