Exception in Thread "main" java.lang.NoSuchMethodError:main
Hi Guys,
I am new to this so if anyone can help me. I have complied my Java servlet successfully but when running it, I get the nosuchmethod error:main
I am using java,mysql and tomcat 5. I am running the program from the prompt on Windows XP.
Thanks Kindly
Naren Gokal
[301 byte] By [
gokala] at [2007-11-27 3:28:40]

# 1
So you want to invoke a servlet class as a Java Application? I shall not ask why you want to do that, but I can tell that when you want to execute a Java Application you need to specify the default 'main' method in the class.public static void main(String[] args) {}
# 2
I think that in core java it is necessary to hav main method,& not in servlets.Have u set classpath before compiling?
# 3
Just set path environment variable & try to compile after that.
# 4
Hi...
Why are you invoking servlet from console?
look, servlets are container managed components, you don need to invoke it, insted container will invoke it...
you just need to extend, HttpServlet class and override service() method,
if you are new to servlet, find some tutorial...
regards,
Sudhir
http://www.jyog.com
# 5
Hi,
I did have a look at servlet examples and still i have no luck.
What I have done is (for testing purposes):
1. Created an HTML file with a button that calls HelloWorld.java
2. I copied teh HelloWorld Servlet and complied this, using javac
3. I then ran the program using "java"
4. I still get the above error.
I did read that with servlets, you don't need a "main" method.
Thanks
Naren.
# 6
If you want to access a Servlet, you don't use a console but web browser.You should deploy your Servlet class in a Servlet Container(e.g. tomcat).And access the Servlet through web browser (e.g. Internet Explorer)
# 7
Okay, Thanks ....
I have just compiled the code (i.e HelloWorld.java) ..
I have opened my HTML document using my browser, and clicked on the subnit button. I get an error:
"The requested resource (/prgmsrc/HelloWorld) is not available. "
I have changed the server.xml file to include the context part.
I have alos changed web.xml to say :
<servlet>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
Can you please advise, what else am i doing wrong.
Thanks guys ...
# 8
Have you got this in your web.xml ?<servlet-mapping><servlet-name>HelloWorldServlet</servlet-name><url-pattern>/HelloWorld</url-pattern></servlet-mapping>
# 9
Hi, if you're not ready to learn/worry about configuring your servlet to be contained in a servlet-supporting webserver, which you must also install and configure, then I would recommend simply installing the NetBeans IDE, which manages all of this for you. It is available at NetBeans.org. Basicaly, you use the IDE's wizards to open a new project, picking Web Application as the project's type, add a new class to the project, picking Servlet as the class's type, add your form to index.html, add your form-processing to the servlet's processRequest method, and hit Run. The IDE takes care of everything else, but I would recommend studying all of the generated files as a learning aid. Basic tutorials come bundled with the IDE, which well document the above process. If you need more help, just ask, I'll help clarify if I can.
Good luck, and happy learning, Jasper
Organically Grown Co