Discussions

Web tier: servlets, JSP, Web frameworks: tomcat uri map

  1. tomcat uri map (1 messages)

    please see my code:
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //Home.java
    package com.mansion;
    import java.util.*;
    import java.io.*;
    public class Home{
    public String getHome() throws Exception{
    Properties p=new Properties();
    FileInputStream fis=new FileInputStream("propfile.txt");
    p.load(fis);
    String home=(String)p.get("HOME");
    return home;
    }
    }
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //TestHome.java
    package com;
    import com.mansion.*;
    public class TestHome{
    public static void main(String[] argv){
    Home home=new Home();
    try{
    System.out.println(home.getHome());
    }catch(Exception e){
    System.out.println(e.getMessage());
    }
    }

    }
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //TestHomeServlet.java
    import javax.servlet.*;
    import com.mansion.Home;
    import java.io.*;
    import javax.servlet.http.*;
    public class TestHomeServlet extends HttpServlet{
    public void doGet(HttpServletRequest req,
    HttpServletResponse resp)
    throws IOException,ServletException{
    try{
    Home home=new Home();
    System.out.println(home.getHome());
    }catch(Exception e){
    System.out.println(e.getMessage());
    }
    }
    }
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    i put my files under the path as:
    C:\jakarta-tomcat-4.0\webapps\ee\WEB-INF\classes\<b>TestHomeServlet.class</b>
    C:\jakarta-tomcat-4.0\webapps\ee\WEB-INF\classes\com\<b>TestHome.class</b>
    C:\jakarta-tomcat-4.0\webapps\ee\WEB-INF\classes\com\mansion\<b>Home.class</b>
    C:\jakarta-tomcat-4.0\webapps\ee\WEB-INF\classes\<b>propfile.txt</b>

    what i mean is to test the "Home.class" by "TestHome.class" and "TestHomeServlet.class" seprately(the "Home.class" use the "java.util.Properties" class to read a text file-"propfile.txt"),when i run the TestHome class in the dos windows,it works well,but when i start my tomcat4,and in the browser,i input "http://127.0.0.1:8080/ee/servlet/TestHomeServlet",the servlet tell me that the system can't find the file "propfile.txt",it seem like that i haven't configured the uri path of tomcat4 correctly,i have tried to put the "propfile.txt" file anywhere under the "....\ee\",they neither work,why?

    thank you very much!

    Threaded Messages (1)

  2. tomcat uri map[ Go to top ]

    You may want to take a look at the struts code for ActionServlet. It takes a config file (specified in web.xml) and somehow finds that.