note: create a dynamic web project in eclipse.
# this is index.jsp #
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<a href="signup.html">new user click here</a>
<hr>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="tadak.jsp" method="post">
<fieldset>
<legend>the world of facts</legend>
<input type="radio" name="choice" value="i">
include
<br>
<input type="radio" name="choice" value="f">
forward
<br>
<input type="radio" name="choice" value="r">
redirection
<br>
<input type="submit" value="test all">
</fieldset>
</form>
</body>
</html>
</body>
</html>
================================
# this is signup.html #
================================
# this is tadak.jsp #
================================
# this is bhadak.jsp #
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<img src="t.jpg" height="150" width="150">
</body>
</html>
================================
# this is error-hanlder.jsp #
# this is index.jsp #
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<a href="signup.html">new user click here</a>
<hr>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="tadak.jsp" method="post">
<fieldset>
<legend>the world of facts</legend>
<input type="radio" name="choice" value="i">
include
<br>
<input type="radio" name="choice" value="f">
forward
<br>
<input type="radio" name="choice" value="r">
redirection
<br>
<input type="submit" value="test all">
</fieldset>
</form>
</body>
</html>
</body>
</html>
================================
# this is signup.html #
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="signup-handler.jsp" method="post">
<fieldset>
<legend>signup</legend>
name
<br>
<input type="text" name="username" required>
<br>
password
<br>
<input type="password" name="password" required>
<br>
email
<br>
<input type="email" name="email" required>
<br>
mobile
<br>
<input type="text" name="mobile" required>
<br>
<input type="submit" value="signup">
</fieldset>
</form>
</body>
</html>
================================
# this is signup-handler.jsp #
# this is signup-handler.jsp #
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%--import a package in jsp --%>
<%@ page import="java.sql.*" %>
<%-- specify the name of jsp that will handle
the exception for this jsp --%>
<%@ page errorPage="error-handler.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%-- jsp comment --%>
<!-- html comment -->
<%
// comment for scriptlet tags
// fetch the data of html form
String un = request.getParameter("username");
String ps = request.getParameter("password");
String em = request.getParameter("email");
String mo = request.getParameter("mobile");
// load driver class
Class.forName("com.mysql.jdbc.Driver");
// get connection
Connection co = DriverManager.getConnection
("jdbc:mysql://localhost:3306/june_27",
"root","root");
// get statement
Statement st = co.createStatement();
// execute sql statement
st.executeUpdate
("insert into user values('"+un+"','"+ps+"','"
+em+"','"+mo+"')");
// close connection
co.close();
%>
<script type="text/javascript">
alert("data has been saved");
</script>
<a href="index.jsp">goto home page</a>
</body>
</html>
================================
# this is tadak.jsp #
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
// fetch html form data
String ch = request.getParameter("choice");
if(ch.equals("i"))
{
%>
<jsp:include page="bhadak.jsp"/>
<%
}
else if(ch.equals("f"))
{
%>
<jsp:forward page="bhadak.jsp"/>
<%
}
else
{
System.out.println("i am else");
response.sendRedirect
("http://localhost:8080/apne-paraye/signup.html");
}
%>
<img src="k.jpg" height="150" width="150">
</body>
</html>
================================
# this is bhadak.jsp #
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<img src="t.jpg" height="150" width="150">
</body>
</html>
================================
# this is error-hanlder.jsp #
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page isErrorPage="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<i>
something went wrong
</i>
<hr>
<img src="k.jpg" width="200" height="200">
<hr>
<a href="signup.html">retry to signup</a>
</body>
</html>
👍🏻
ReplyDelete