Solved

jsp Beginners question - how do I interpret the INCLUDE statement

Posted on 2010-08-22
12
632 Views
Last Modified: 2013-11-24
I am having to check/edit some jsp code because my developer has gone awol! My background is in MS SQL with a basic understanding of ASP so please excuse the simplicity of the question.

I am running a simple WAP site.
When I start Tomcat (5.5.30) I notice a file being sought - wurfl.xml.
TOMCAT OUTPUT:
Last try. Looking for wurfl.xml in temp directory
C:\temp\wurfl.xml found! I'll use this
trying to see if we can figure out the patch file
potential patchfile: C:\temp\wurfl_patch.xml
Patching OK. Applied
WURFL has been initialized

Searching the code I find the following reference:
<%@page import="net.sourceforge.wurfl.wurflapi.ListManager"%>

Where should I put the wurfl.xml and _patch files?
0
Comment
Question by:Bird757
12 Comments
 
LVL 10

Expert Comment

by:Pramod Kumar
ID: 33498578
it is a sourceforge opensource project. For detail you may visit the respective page on http://sourceforge.net
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 33498579
put it it web-inf floder
0
 

Author Comment

by:Bird757
ID: 33500716
I have checked the SourceForge site - not being a linux/unix developer myself I am not used to open source sites and have been unable to find anything helpful. There is a big disclaimer on the site saying a person who asks a dumb question will be banned! I know my questions at this time are really basic so am asking here instead of trying to follow threads I have no knowledge of.

OK the idea of putting the file in the web-inf folder I had already tried - no luck there.

I have placed the file in c:\temp (and that works) - but that is not a good place in my opinion.

The debug suggestion is to create a wurfl.properties file, and invlude the path in that file. I have done this (creating a text file, renaming to wurfl.properties, adding into that file the path to wurfl.xml) - still no luck.

As soon as I delete (rename) the wurfl.xml in c:\temp Tomcat throws an error (I have pasted the error below) ... and this error also suggests initialising in initFromWebApplication() - but I can't find this anywhere in the existing code.

I am sure this is all straight-forward for someone familiar with JME and jsp - this is my first poke around in the code and I have no idea where to start.

The Tomcat Error output is below - any guidance will be great:
Last try. Looking for wurfl.xml in temp directory
WURFL not found anywhere
You have 3 possibilities:
- define wurfl.properties in the same directory
  as your application and provide the wurfl.xml path
  ex: wurflpath = file://C:\projects\wurfl\resources\wurfl.xml

- place wurfl.xml in either C:\temp (Windows) or /tmp (Unix)

In a servlet environment, initFromWebApplication() can be used to initialize
using the wurfl at /WEB-INF/wurfl.xml

- the API will also look at the 'wurflpath' System property
0
 
LVL 27

Expert Comment

by:rrz
ID: 33502348
>how do I interpret the INCLUDE statement  
Which include statement are you referring to ?

I haven't used this API but I took a quick look. I saw  
http://wurfl.sourceforge.net/faq5.php#570  
Please look in your web app's  WEB-INF/Classes directory.  
If you find the file
Init.java  
or the file  
WurflServletInit.java  
then post them here.  
Maybe one of us will be able to help you.  
Also, check and see if the files WurflServletInit.class or Init.class is located in the WEB-INF/Classes directory.
0
 
LVL 27

Expert Comment

by:rrz
ID: 33503086
I found this page too.
http://wurfl.sourceforge.net/njava/
It says  
"web.xml is the easiest way to configure the API for your needs."
Please post your web app's   web.xml  
0
 

Author Comment

by:Bird757
ID: 33504769
Thanks rrz - that looks like a link worth going through in detail.

I think there is something very basic I am missing here. It is not easy taking over some code without any idea of how it should be structured.

On the web.xml = I did notice earlier my developed did not have a web.xml file so I copied one from another project and have edited the very basics in it (I have no idea what I am doing here I do admit). What I have is below. I added the reference to wurfl.zip but still no luck. It keeps looking in c:\temp for it.

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
      <display-name>UTrackIT</display-name>
      <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>

<context-param>
  <param-name>wurfl</param-name>
  <param-value>/WEB-INF/wurfl.zip</param-value>
</context-param>

      <session-config>
        <session-timeout>
            15
        </session-timeout>
    </session-config>
   
 
</web-app>






The Tomcat startup reports the info below (if this is helpful)
23 Aug 2010 7:47:03 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performanc
e in production environments was not found on the java.library.path: C:\jdk1.5\b
in;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;
C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\Dell\SysMgt\RAC5;C:\Program Files (x86)\Dell\SysMgt\oma\b
in;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\
Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\D
TS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Comm
on7\IDE\;C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\
23 Aug 2010 7:47:03 PM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-192.168.100.34-80
23 Aug 2010 7:47:03 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 489 ms
23 Aug 2010 7:47:03 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
23 Aug 2010 7:47:03 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.30
23 Aug 2010 7:47:03 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
----START init DB----
getting the connection took: 453 milli seconds
----DONE init DB----
23 Aug 2010 7:47:04 PM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-192.168.100.34-80
23 Aug 2010 7:47:04 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
23 Aug 2010 7:47:04 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/15  config=null
23 Aug 2010 7:47:04 PM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
23 Aug 2010 7:47:04 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1470 ms
Last try. Looking for wurfl.xml in temp directory
C:\temp\wurfl.xml found! I'll use this
trying to see if we can figure out the patch file
potential patchfile: C:\temp\wurfl_patch.xml does not exist, or is not readable
WURFL has been initialized
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 27

Expert Comment

by:rrz
ID: 33506879
Please tell us what API you are using.
What did you download ?
Where did you get it(show link) ?  

The reason I ask is because it looks like there are two different possibilities.
http://wurfl.sourceforge.net/java/api2docs/net/sourceforge/wurfl/wurflapi/package-summary.html
http://wurfl.sourceforge.net/njava/javadocs/  
The second is the newer one.
If you are using the newer one, then you should try adding  

<listener>
  <listener-class>
     net.sourceforge.wurfl.core.web.WURFLServletContextListener
  </listener-class>
</listener>

to what you already have in your web.xml file.  
0
 
LVL 27

Expert Comment

by:rrz
ID: 33507578
><%@page import="net.sourceforge.wurfl.wurflapi.ListManager"%>  
I think that you are using the API in the first link(in my last post). Don't add the listener tag.
So, that it seem that you are using WurflServletInit.  Go back to my first post and answer the questions I asked there.
0
 

Author Comment

by:Bird757
ID: 33556917
I have found what I need to change - apparently the path is stored in Init.class (source is Init.java) - listed below.

I have 2 problems; the first very basic. How do I compile this .java file to .class? I copy the Init.java to my jdk/bin folder, and run javac.exe Init.class but it can't fine any of the referenced classes? Please help.

Init.java source:

package com;

import net.sourceforge.wurfl.wurflapi.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Init extends HttpServlet {


    /**
       *
       */
      private static final long serialVersionUID = 1L;

      public void init(ServletConfig config) throws ServletException {
            super.init(config);
            //Initialize WURFL with '/WEB-INF/wurfl.xml'
            System.out.println("About to initialize web-app");
            //ObjectsManager.initFromWebApplication(config.getServletContext());
            ObjectsManager.initFromWebApplication("C:\\Tomcat\\webapps\\ROOT\\WEB-INF\\tld\\wurfl.xml","C:\\Tomcat\\webapps\\ROOT\\WEB-INF\\tld\\wurfl_patch.xml");
            //ObjectsManager.initFromWebApplication("C:\\Tomcat\\webapps\\ROOT\\WEB-INF\\tld\\wurfl.xml","C:\\temp\\wurfltest\\anothername.xml");
    }


    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        response.setContentType("text/plain");
        PrintWriter out = response.getWriter();
        out.println("init servlet (Loaded on startup for WURFL initialization)");
    }

    /**
     * We are going to perform the same operations for POST requests
     * as for GET methods, so this method just sends the request to
     * the doGet method.
     */

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        doGet(request, response);
    }
}



Output when I try compile:

C:\jdk1.5\bin>c:\jdk1.5\bin\javac Init.java
Init.java:3: package net.sourceforge.wurfl.wurflapi does not exist
import net.sourceforge.wurfl.wurflapi.*;
^
Init.java:5: package javax.servlet does not exist
import javax.servlet.*;
^
Init.java:6: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
Init.java:8: cannot find symbol
symbol: class HttpServlet
public class Init extends HttpServlet {
                          ^
Init.java:16: cannot find symbol
symbol  : class ServletConfig
location: class com.Init
        public void init(ServletConfig config) throws ServletException {
                         ^
Init.java:16: cannot find symbol
symbol  : class ServletException
location: class com.Init
        public void init(ServletConfig config) throws ServletException {
                                                      ^
Init.java:26: cannot find symbol
symbol  : class HttpServletRequest
location: class com.Init
    public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
                      ^
Init.java:26: cannot find symbol
symbol  : class HttpServletResponse
location: class com.Init
    public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
                                                  ^
Init.java:26: cannot find symbol
symbol  : class ServletException
location: class com.Init
    public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {

                    ^
Init.java:38: cannot find symbol
symbol  : class HttpServletRequest
location: class com.Init
    public void doPost(HttpServletRequest request, HttpServletResponse response)
 throws IOException, ServletException {
                       ^
Init.java:38: cannot find symbol
symbol  : class HttpServletResponse
location: class com.Init
    public void doPost(HttpServletRequest request, HttpServletResponse response)
 throws IOException, ServletException {
                                                   ^
Init.java:38: cannot find symbol
symbol  : class ServletException
location: class com.Init
    public void doPost(HttpServletRequest request, HttpServletResponse response)
 throws IOException, ServletException {

                     ^
Init.java:17: cannot find symbol
symbol  : variable super
location: class com.Init
                super.init(config);
                ^
Init.java:21: cannot find symbol
symbol  : variable ObjectsManager
location: class com.Init
                ObjectsManager.initFromWebApplication("C:\\Tomcat\\webapps\\ROOT
\\WEB-INF\\tld\\wurfl.xml","C:\\Tomcat\\webapps\\ROOT\\WEB-INF\\tld\\wurfl_patch
.xml");
                ^
14 errors

C:\jdk1.5\bin>
0
 
LVL 27

Accepted Solution

by:
rrz earned 500 total points
ID: 33559914
You have to tell the compiler where to look.
Please try something like  
C:\jdk1.5\bin>c:\jdk1.5\bin\javac -classpath C:\Tomcat\lib\servlet-api.jar;<path>/net/sourceforge/wurfl/wurflapi/ObjectsManager Init.java  
where  
<path>  is the location where you put the wurfl classes  
Or if the wurfl classes are in a jar, then try  something like  
C:\jdk1.5\bin>c:\jdk1.5\bin\javac -classpath C:\Tomcat\lib\servlet-api.jar;<path>/wurfl.jar Init.java
0
 

Author Comment

by:Bird757
ID: 33576638
This is a note to say Thanks for the feedback. I am working through the comments.
0
 

Author Closing Comment

by:Bird757
ID: 34028809
Thanks for the help. I ended up struggling to get the path elements correct and ended up contracting someone who knew what they were doing; and he added a library that Apache needed that was not in any of the class paths - and installed ANT; Problem solved. I appreciate the help.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now