Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

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
0
n2alexan
Asked:
n2alexan
  • 7
  • 6
  • 3
1 Solution
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 7
  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now