aspose file tools*
The moose likes Servlets and the fly likes package issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "package issue" Watch "package issue" New topic
Author

package issue

pravin suroshe
Greenhorn

Joined: Jan 13, 2005
Posts: 8
Hi all,

I am using package in my servlets, the folder structure for the same package looks like the following:
D:Servlets\Mypackage\coreservlets

in coreservlets directory, I have two folders as, Application and Helpers

in Application folder I have the following servlet code:

package coreservlets.Application;

import coreservlets.Helpers.ServletUtilities;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import java.io.PrintWriter;

public class HelloWWW3 extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response. getWriter();
out.println(ServletUtilities.headWithTitle("Hello WWWW")+"<body>Hello</body></html>");
}
}


in Helpers folder I have the following servlet code:

package coreservlets.Helpers;
public class ServletUtilities
{
public static String headWithTitle(String title)
{
return ("<html><head><title>"+title+"</title></head>");
}
}


Settings in web.xml is as follows:

<servlet>
<servlet-name>HelloWWW3</servlet-name>
<servlet-class>HelloWWW3</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloWWW3</servlet-name>
<url-pattern>/HelloWWW3</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>ServletUtilities</servlet-name>
<servlet-class>ServletUtilities</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>ServletUtilities</servlet-name>
<url-pattern>/ServletUtilities</url-pattern>
</servlet-mapping>


I am using Tomcat 5.0 server, and for coding purpose I am using IntelliJIdea 3.0.5

when I compile these two programs it creates folder structure as coreservlet\Application\HelloWWW3.class and coreservlet\Helpers\ServletUtilities.class in C:\Tomcat 5.0\webapps\Mysite\WEB-INF\classes path....that is ok!!!

I run servlet in Internet Explorer as http://localhost:8080/Mysite/coreservlets.HelloWWW3
I have also tried http://localhost:8080/Mysite/Application.HelloWWW3
but, it's not working by giving me error as "The requested resource (/Mysite/coreservlets.HelloWWW3) is not available."

Could anyone explain me what I am doing wrong..???...

Thanx in advance
Pravin
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Just use what you set up in your mapping:

http://localhost:8080/Mysite/HelloWWW3


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by pravin java:
<servlet>
<servlet-name>HelloWWW3</servlet-name>
<servlet-class>HelloWWW3</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloWWW3</servlet-name>
<url-pattern>/HelloWWW3</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>ServletUtilities</servlet-name>
<servlet-class>ServletUtilities</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>ServletUtilities</servlet-name>
<url-pattern>/ServletUtilities</url-pattern>
</servlet-mapping>


- Your class ServletUtilities is not a servlet.

Entry should be like this



I am changing "coreservlets.Application" to "coreservlets.application" to comply with the naming convention. Moreover, I am not showing the entry of your other servlet because it is not qualifying as Servlet.
gaurav chhabra
Ranch Hand

Joined: Jul 24, 2004
Posts: 109
hi buddy
like u have different directory structures ,,,,u r using servlets and in servlets the thing is...........

1) u have to compile the servlet
2) create directory in tomcat5.0\name_of_prog
3) then in name_of_prog to directories META-INF and WEB-INF
4) in WEB-INF make two classes "classes" and "lib"
5) in classes put the compiled file..
6) then make a .xml file as u make and store it in WEB-INF
7) then copy the WEB-INF folder in tomcat5.0/webapps/root/

and then write the proper url and keep the packages in mind

best of luck
and feel free to contact
gaurav
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"pravin java",
please see the warning about your display name here.

"pravin_indai" was not valid and neither is "pravin java".

We require display names to be two words: your first name, a space, then your last name. Fictitious names are not allowed. Please edit your profile again and correct your display name, since accounts with invaid display names get deleted, often without warning

thanks,
Dave.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package issue
 
Similar Threads
A problem in executing the servlet
How to call a servlet
welcome file list
welcome file list
welcome file list