File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes help on controller jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "help on controller jsp" Watch "help on controller jsp" New topic
Author

help on controller jsp

Clarice Lin
Greenhorn

Joined: Jan 16, 2003
Posts: 10
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>
Roger Graff
Ranch Hand

Joined: May 29, 2001
Posts: 112
In your forward tags, you have
<jsp:forward url="index.jsp" />
try this:
<jsp:forward page="/index.jsp" />
Note the forward slash just before index.jsp.
Roger Graff
Ranch Hand

Joined: May 29, 2001
Posts: 112
in testcontroller.jsp, why not have the href point directly at scontroller.jsp directly (instead of including scontroller in test1.jsp). Are you using a web.xml file? If you are you can define a default page under the "welcome-file-list" attribute.
<!-- *** in testcontroller.jsp *** -->

<!-- *** web.xml *** -->

In your scontroller.jsp:

If you choose to do it this way, you won't need to include scontroller in test1.jsp. I also noticed in your original code that you didn't use the <jsp aram> tag correctly. The param tag is a sub tag, so it needs to be surrounded by <jsp:include></jsp:include> or <jsp:forward></jsp:forward> or whatever other JSP tags support it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help on controller jsp
 
Similar Threads
Problem after deploying my session,entity,and web component
Deploying Servlets/JSP on Linux w/Tomcat
Request Attribute confusion
Deploying Servlets on Linux
Deploying Servlets/JSP on Linux w/Tomcat