?
Solved

where to put my servlet in Tomcat directory?

Posted on 2003-03-26
11
Medium Priority
?
186 Views
Last Modified: 2011-09-20
Dear experts,

I know this must be elementary. I wrote a servlet and in my JSP, i have a <form name=xxx action="servlet" method="post">. However, I keep getting error message saying it could not find my servlet.

I put all my Java class under web-inf\myPackage\, all the JSP under ROOT, and servlet also under web-inf\myPackage since it is in the same package as my other Java class. Thanks for any help.

0
Comment
Question by:changcy77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
11 Comments
 

Author Comment

by:changcy77
ID: 8213776
Oop! In fact, I put both my Java class and Servlet under WEB-INF\class\myPackage\

thanks.
0
 
LVL 28

Expert Comment

by:rrz
ID: 8213825
>I put both my Java class and Servlet under WEB-INF\class\myPackage\
Do you mean that you put them in ?
WEB-INF/classes/myPackage/
0
 

Author Comment

by:changcy77
ID: 8213881

yes.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Expert Comment

by:rrz
ID: 8213913
What version of Tomcat?
>all the JSP under ROOT
do you mean that you using the context ROOT that came with Tomcat ?
Why not just create your own context?
0
 
LVL 28

Accepted Solution

by:
rrz earned 120 total points
ID: 8214084
If you have the invoker servlet, working then try
action="/servlet/myPackage.yourservletname
But the prefered way is to map your servlet in your web.xml file.
0
 
LVL 2

Expert Comment

by:amit_chauhan
ID: 8215126
Hi,
You need to register your servlet in web.xml file.
Put this entry in the web.xml (stored in WEB-INF directory) file under <web-app> tag:

<servlet>
  <servlet-name>myservlet</servlet-name>
  <servlet-class>myPackage.servletClass</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>myservlet</servlet-name>
  <url-pattern>/myservlet</url-pattern>
</servlet-mapping>


Make sure <servlet-mapping> tag appear after all <servlet> tags are finished.

Now change your <form> tag's action to this :
<form name="xxx" action="myservlet" method="post">


Hope that helps
Thanks
Amit
0
 
LVL 28

Expert Comment

by:rrz
ID: 8218208
To amit,
><form name="xxx" action="myservlet" method="post">
You are using relative url, I don't think that will work.
I would use
action="<%=request.getContextPath()%>/myservlet"
But if changcy puts the servlet in ROOT without mapping and using invoker, then use
action="/servlet/myPackage.myservletname
0
 
LVL 2

Expert Comment

by:amit_chauhan
ID: 8219700
Sure, You can prepend request.getContextPath () to the servlet name. What I gave is just an example. It will work if its called from the same hierarchial level, i.e. root level, like the way it works in MVC architecture. But prepending request.getContextPath () would be a better idea.
About using the invoker servlet, I think that may not be the best idea. And besides this will only work if you are using ROOT as your webapp (I think !:). And second it could pose security risks.

Thanks
Amit
0
 

Author Comment

by:changcy77
ID: 8230527


Thanks very much. I did registered my servlet. Now, I am getting "servelet not available" message, why?

I have tried to put my servlet under
1.ROOT
2.ROOT\mypackage\
3.WEB-INF\class\myPackage\


Thanks.
0
 
LVL 28

Expert Comment

by:rrz
ID: 8232767
>I did registered my servlet.
Where ?
if in web.xml in ROOT then
Put servlet in
ROOT/WEB-INF/classes/myPackage/
But you should just go ahead and create your own context.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
Check out the latest tech news, community articles, and expert highlights in August's newsletter.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question