Link to home
Start Free TrialLog in
Avatar of n2alexan
n2alexan

asked on

Configure using beans in sub directories. Works ok in the root of the site directory.

Hi,

I have the following set up:

Website root directory with jsp page datatest.jsp that works and get info from a JavaBean. I have also the same copy of the page but in my subdirectory 'pages' and this page does not work. What do I need to change so that the same JavaBean is picked by pages in that directory.

Many thanks
Avatar of Mick Barry
Mick Barry
Flag of Australia image

shouldn't need to do anything.
can u post the page that isn't working and the error you're getting
Avatar of n2alexan
n2alexan

ASKER

sure

the one that works

http://www.nichefhgs.com/datatest.jsp

the one that does NOT work

http://www.nichefhgs.com/pages/datatest.jsp
can u post the source?

where is the class framework.Datatest?

it should be in WEB-INF/classes/framework/Datatest.class
yep, the class in this directory.

the class code is this
=========
package framework;

public class Datatest {
   
    /** Creates a new instance of datatest */
    public Datatest() {
    }
   
    public String getName() {
        return "Nataliya Alexander";
    }
   
    public String getDrinkName() {
        return "Tea and Coffee";
    }
   
   
}
=========
the jsp page code is
=========
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>

<!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=UTF-8">
        <title>This is data test</title>
    </head>
    <body>

    <h1>JSP Page</h1>
   
   
    <%
       
       framework.Datatest dt;
       framework.Datatest dataTest = new framework.Datatest();
       
       out.print(dataTest.getName() + "<br />");
       out.print(dataTest.getDrinkName());

    %>
   
       
    </body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Could this be something to do with server.xml or web.xml configurations?
no, not that i'm aware of.
Might be worth asking your isp, have you tested it locally
it works ok on my machine but I used bundled Tomcat
Maybe you could  try using the following on each page.  
<jsp:useBean id="myBean" class="framework.Datatest "/>
and  to access  
<%
       out.print(myBean.getName() + "<br />");
       out.print(myBean.getDrinkName());
%>
or use
<%=myBean.getName()%> <br/>
Actually, I have figured out an answer. All I had to do is to copy META-INF and WEB-INF directories in that subdirectory and it now works. I do not understand why this have to be like that.

N.
that sounds like its treating every directory as a seperate web application, that could become annoying after a while.
Your ISP can probably tell u whats going on, probably related to their config.
hmm, I had a bit of a nightmare setting things up. I'll query my host again. Thank you very much for help.
As the objects answer

> all I can think of is that for some reason its not treating the pages subdirectory as being in that webapp.

was the one that helped me to solve the issue, I am giving points to him.

Thank you very much for your help.
N.
no worries :)
What does the following output on each page ?  
<%=request.getContextPath()%>    
sure

the one that did work

http://www.nichefhgs.com/datatest.jsp

there is nothing printed

the one that did NOT work

http://www.nichefhgs.com/pages/datatest.jsp

"/pages" is printed
>there is nothing printed    
It is probably in the ROOT  web app.
>"/pages" is printed  
Anyway they are different contexts. Just as objects posted.