Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
878 views
in Technique[技术] by (71.8m points)

java - Class "<CLASS_NAME>" nether has a main method nor its servlet specified in file web.xml

I am using NetBeans 7.1 and made a servlet in it. Now when I am running it, it is giving me

Class ' ' neither has a main method nor its a servlet specified in web.xml

After this, it is showing me one more error:

class ' ' does not have a main method"

I can't figure out what the problem is. I have uninstalled and installed the NetBean twice but no help. The servlet is just an ordinary servlet with no logic in it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

After a long search I got what I feel is the answer. Just add:

@WebServlet (name="name of servlet",urlPatterns={"/url patter of servlet"})

above your class. This worked for me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...