I have some problems with passing control between jsp pages. Was trying out a controller page.What i have come up with.
testcontroller.jsp page will haf a hyperlink n a session attribute passed to test1.jsp.
When the user clicks on the hyperlink, it is supposed to go to test1.jsp.
on test1.jsp, i have included the page scontroller.jsp.
in scontroller.jsp, it is supposed to test whether the session attribute exists. If it is null, the page will be redirected to another page called index.jsp(instead of showing the page test1.jsp)
the main problem is when a user clicks on a hyperlink for eg test.jsp, on test.jsp itself, unless the user is identified, the page will not be shown to the user. that is y i have come up with the code though i think somehow the passing and checking of session attribute is unsuccessful.
thank you for helping=)
below is the code for testcontroller.jsp
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<% session.setAttribute("allowUserId","");%>
<a href="test1.jsp">click here</a>
</body>
</html>
here is the code for scontroller.jsp
<%@ page language = "java" import = "java.sql.*" import = "java.lang.*","java.sql.*"
import="javax.servlet.http.HttpSession.*"%>
<jsp:useBean id = "db" class = "javabeans.DbAccess" scope = "session" />
<%-- check to see if user has logged in yet
note: login is not part of this application,
so user is redirected to the login application
--%>
<% if (((String)session.getAttribute("allowUserId")) == null) { %>
<jsp
aram name="action" value="failed" />
<jsp:forward url="index.jsp" />
<% } %>
here is the code for test1.jsp
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<jsp:include page="scontroller.jsp"/>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<%=session.getAttribute("allowUserId")%>
letz c this!
</body>
</html>