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
n2alexanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
shouldn't need to do anything.
can u post the page that isn't working and the error you're getting
0
n2alexanAuthor Commented:
sure

the one that works

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

the one that does NOT work

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

where is the class framework.Datatest?

it should be in WEB-INF/classes/framework/Datatest.class
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

n2alexanAuthor Commented:
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>
0
objectsCommented:
that all looks fine, not sure why you're getting that error
all I can think of is that for some reason its not treating the pages subdirectory as being in that webapp.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
n2alexanAuthor Commented:
Could this be something to do with server.xml or web.xml configurations?
0
objectsCommented:
no, not that i'm aware of.
Might be worth asking your isp, have you tested it locally
0
n2alexanAuthor Commented:
it works ok on my machine but I used bundled Tomcat
0
rrzCommented:
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/>
0
n2alexanAuthor Commented:
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.
0
objectsCommented:
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.
0
n2alexanAuthor Commented:
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.
0
objectsCommented:
no worries :)
0
rrzCommented:
What does the following output on each page ?  
<%=request.getContextPath()%>    
0
n2alexanAuthor Commented:
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
0
rrzCommented:
>there is nothing printed    
It is probably in the ROOT  web app.
>"/pages" is printed  
Anyway they are different contexts. Just as objects posted.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.