Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package issue

 
pravin suroshe
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic