Animesh Gupta

Greenhorn
+ Follow
since Jul 14, 2010
Merit badge: grant badges
For More
Mumbai, India
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Animesh Gupta

Hey Rene,
Kudos ... you gave me an alternate solution as well.

Really cool. It worked fine all the way.

Thanks and Regards
Animesh
13 years ago
Hey Martin/Rene,
Thanks for the replies.

Martin man you cracked it. I was like laughing and thinking about how did it missed that second classpath setting.

And yes that is a Sierra/Bates book's example. Are you a programmer detective ?
Actually I am new to servlet programming. So, I was trying out the example given in the book.

Thanks a lot you saved me lots of time.

Hey Rene, Thanks for your effort as well. I tried out your way of putting up the command line. But, it again threw the same error saying


But thanks anyways. I appreciate your effort of going through the previous posts and putting up a suggestion.

Thanks and Regards
Animesh
13 years ago
Ok Martin,
first of all I would like to say thanks for all your effort for getting around my problem. Thanks

Let me tell you little more ... My directory structure is like

and


I have to compile and deploy these files at the following locations

and


The command I am using at command prompt is like this


Simplifying the above command, I am placed at

that I am at the base of my package structure, i.e., at the base of "com" directory.
Now, I have to include the servlet-api.jar in the classpath

deploying at

sourcepath is set at

the source file is at


This is the whole situation.

Might be that your classes are not public?


Both my classes Expert and Selector are declared public.

Thanks and Regards
Animesh.
13 years ago
Hi,
No luck with the above suggest as well.

I would like to simplify my prob. I have 2 source files. One is compiled and I am using this compiled file as an import in my other source file.

Both the source files are in different packages.

When I go ahead and compile my source file which using the other one as an import then I get the error stating that the package which I have used as the import does not exists.

I have tried to compile setting that package in classpath as well. But, no luck.
I have used various compiling options with javac, like, -classpath, -cp, -sourcepath, but still no luck.

The directory structure I am having is like this


and


I am trying to import into

Help needed regarding how to compile successfully Selector.java

Thanks and Regards
Animesh

13 years ago
Hi Martin,
Thanks for the prompt reply.

1.) The package -- com.example.model does exists.

2.) The Expert.java class does have the package declaration as

3.) The directory structure is right. Both the packages, web and model fall under the package com.example.

4.) The Expert.java class is compiled.

5.) The actual code is too long to paste here. I am pasting the imports for you in both classes

For Selector.java



For Expert.java



6.) Why do I need to add Exper.java in my CLASSPATH ?

7.) When I tried by adding the class Expert.java in my CLASSPATH, still I got the same error



Really going nuts with problem. No obvious reason for which it is not working.

Thanks and Regards
Animesh
13 years ago
Hi All,
I was doing fine with my code until I scribbled an import for my custom made class.

The scenario is, I have a class Selector. it is inside the package .
Now, I am trying to import another class called Expert.java which is in the package .

is trying to use the class .
The import I wrote -- inside the Selector.java class.

No when I am trying to compile the class Selector.java from the command prompt and I am getting error saying



Hey guys please help for how to compile my file Selector.java. It is important as I have to finish this by tonight.

Any kind of help will be really appreciated.

Thanks and Regards
Animesh
13 years ago
Hi All,
I got stuck with my first tomcat deployment. I am very new at this so finding difficulty to resolve the issue. Please help me out.

I am using Tomcat 7.0 on windows vista OS. As the tomcat service cannot start on windows vista. I downloaded the tomcat source and built it with apache ant.
Now, I am able to start and stop the server from the command prompt.

The directory structure is webapps>ROOT>MyApp>WEN-INF>classes.

In my html file I have the action set as follows ::--

In the web.xml I am having ::--

When I tried to perform the action on html page it gave a message

Now, I changes the " PickChoose to Picker " in both web.xml and html file. I shut down the server and restarted it from the command prompt.

Again I performed the action on the html and the message I got was ::--

But, I changed the PickChoose to Picker. How did it gave me the old name, i.e., PickChoose ?

I am not able to run my app, guys help me with some insight.

Thanks and Regards
Animesh
13 years ago
Hi David Newton,

Thanks for the reply.
I am kind of new to servlet programming so little bit beating around the bush.

Anyways you helped me to see things little more clearly regarding the servlets.
I will keep posting doubts as I am relatively new to servlet coding.

Thanks and Regrads
Animesh
13 years ago
Hi Bear Bibeault,
Thank you for the prompt reply.

I have a couple questions to put up.

The concrete implementation for all of those (except for Servlet, which you provide) is provided by the container; Tomcat for example. The fact that they are interfaces means that you have no need to be concerned about the concrete classes. You always code to the interface.



1.) I want to see the implementation to know how the servlet container creates instances and invoke the servlet life-cycle methods. Is there a way to know this ?

No, the container creates an instance of your SimpleServlet class.



2.) There is the problem. Unless I provide my custom class, it doesn't exists. So, how does servlet container gets to know that it has to create an instance of my class, i.e., the class SimpleServlet ? Let us suppose if the servlet container creates an instance of Servlet and then downcasts it to my class, i.e., the SimpleServlet, then shouldn't there be a ClassCastException beacuse of down-casting ?

I am sorry if you find these questions very basic. But, I am feeling little curious to know the mechanism how this thing works end to end.

Thanks and Regards
Animesh.
13 years ago
Hi All,
I am very new with servlet programming. I have a confusion regarding the way servlets work.

1.) I have seen the servlet API and whatever I see, like, Servlet, HttpServletRequest, HttpServletResponse, ServletRequest, ServletResponse, are all interfaces. Where is the concrete implementation for these interfaces ?

2.) I have read all around that servlet container creates the instance of the servlet. But, how does it do when javax.servlet.Servlet is an interface ?

3.) The servlet container calls the init(), service and destroy methods for a complete servlet lifecycle. Let me take an example.

<code> public SimpleServlet extends HttpServlet {

@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
getServletContext().log("init() called");
count=0;
}

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
getServletContext().log("service() called");
count++;
response.getWriter().write("Incrementig the count: Count = "+count);
}

@Override
public void destroy() {
getServletContext().log("destroy() called");
}
}
</code>

My question is how does the servlet container know that init(), service() and destroy() methods are overridden under the class SimpleServlet, i.e., my custom class ?

The servlet container creates and instance of javax.servlet.Servlet to call init(), service() and destroy() methods and not an instance of my class SimpleServlet. Then how does these methods get called ?

I will really appreciate any help from you all.

Thanks and Regards
Animesh
13 years ago