Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current directory is varying depending on direction of page load.

Status
Not open for further replies.

chard21

Programmer
Dec 25, 2005
1
US
My current directory is changed based on the direction a '.jsp' page is being loaded: whether by initial browser load (via a servlet) or by a link within an internal '.jsp' page (which is also via a servlet).

I've attepted to include some code snippets below to help.

Description:
I have a '.jsp' page called welcome.jsp that is supposed to be the initial page loaded when someone comes to the site. Based on the way things are currently set up, this page is accessed using the following URL:
Since this page will need to display data retrieved from a database, I am attempting to determine when the page is loaded for the first time so that I can 'forward' it to a servlet. (See session_i.jsp below.) The servlet will manage retrieving the database data, saving the data into the session, and invoking the dispatcher to load the welcome.jsp page.

The welcome.jsp page is actually a base page. It contains a number of common areas and an area that will change content depending on the value of the 'Page' session variable. (This was my attempt to not have to replicate any of the common HTML/JSP.)

Currently, the welcome.jsp page can act as a login or as a register page. There is a link on the login page that will invoke the servlet to load the register page. The link to do this is as follows:

<a href="/wad/AccountServlet?"Request"="RequestRedirect"&"Page"="Register">
Register
</a>

There is also a link on the register page that will invoke the servlet to load the login page. The link to do this is as follows:

<a href="/wad/AccountServlet?"Request"="RequestRedirect"&"Page"="Login">
Login
</a>

Problem:
The easiest way to see my problem is to view the section where the appropriate JavaScript file is being loaded. When a client's browser attempts to load the page the source file is referenced by src="welcome_login.js" even though the load actually came as a result of the servlet (since the session_i.jsp would have forwarded to the servlet). When an internal link is used to load the page the source file is referenced by src="/wad/jsp/welcome_register.js". I'm sure you can see that as soon as I try to follow my link back to the Login page from the Register page, the Login JavaScript file will not be found.

This is my first attempt at developing a web site using Jave/JSP/Servlets soI am most likely not following some accepted standard. Any guidance with organziation, how initial access to a site is normally performed, or just simply how best to get past my current problem would be greatly appreciated.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<!--
-- welcome.jsp
-- - all '.jsp' files located in <tomcat>\webapps\wad\jsp
-- - all '.js' files located in <tomcat>\webapps\wad\jsp
--
-- - session_i.jsp shown below
-->

<%@ include file="session_i.jsp" %>

<html>
<head>
<%
String page = (String) request.getAttribute ("Page");

if (page == null)
{
page = "";
}
%>

<!--
-- Include the appropriate JavaScript file(s).
-->

<%
if (page .equals ("Login"))
{
%>
<script language="JavaScript" type="text/javascript"
src="welcome_login.js">
</script>
<%
}
else if (page.equals ("Register"))
{
%>
<script language="JavaScript" type="text/javascript"
src="/wad/jsp/welcome_register.js">
</script>
<%
}
%>
</head>

<!--
-- Set <body> tag.
-->

<%
if (page.equals ("Login"))
{
%>
<body onLoad="loginSetFocus()">
<%
}
else if (page.equals ("Register"))
{
%>
<body onLoad="registerSetFocus()">
<%
}

<!--
-- Include appropriate content
-->

<%
if (focusPage.equals ("Login"))
{
%>
<%@ include file="welcome_login_i.jsp" %>
<%
}
else if (focusPage.equals ("Register"))
{
%>
<%@ include file="welcome_register_i.jsp" %>
<%
}
%>

</body>

</html>



<!--
-- session_i.jsp
--
-- - servlet located in <tomcat>\webapps\wad\WEB-INF\classes\wad\account
--
-- - web.xml file shown below
-->

<%
String sessionIdApp = (String) request.getAttribute ("SessionId");
String sessionIdHttp = session.getId();

if (sessionIdApp == null)
{
sessionIdApp = "";
}

if (!sessionIdApp.equals (sessionIdHttp))
{
%>
<!-- Forward to a servlet -->
<jsp:forward page="/AccountServlet">
<jsp:param name="Request" value="Redirect" />
<jsp:param name="RedirectPage" value="Login" />
</jsp:forward>
<%
}
%>



<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"
<web-app>

<display-name>WAD</display-name>
<description>
WAD
</description>

<servlet>
<servlet-name>AccountServlet</servlet-name>
<servlet-class>wad.account.AccountServlet</servlet-class>
</servlet>

<!-- Define filter mappings for the defined filters -->

<servlet-mapping>
<servlet-name>AccountServlet</servlet-name>
<url-pattern>/AccountServlet</url-pattern>
</servlet-mapping>

</web-app>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top