Aim:- Write a program using Session that selects the programming language and when Submit button is clicked a page with Session information gets displayed along with the information for selecting another language and other to get recommended books which displays the requested page when clicked.
Software Used:- NetBeans, edge
Coding:-
Index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<pre>
<form action="welcome.jsp">
<select name="language">
<option value="1">JAVA</option>
</select>
<br><input type="submit" value="Click"><br/>
</pre>
</form>
</body>
</html>
Welcome.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String name = request.getParameter("luname");
out.print("<strong>Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. ... Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of the underlying computer architecture." );
session.setAttribute("luser", name); //set attribute in session
%>
<a href = "second.jsp" style="color: red"><br>See Books</a>
</body>
</html>
Second.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<%
String Java=(String)session.getAttribute("lname"); //Getting Session Attribute
out.print("<strong>1:Java: A Beginner's Guide. Author: Herbert Schildt"
+ "<br><strong>2:Effective Java. Author: Joshua Bloch"
+ "<br><strong>3:Head First Design Patterns");
%>
</body>
</html>
0 Comments
if you have any problem, please let me know