-1

For my domain (palibacsi.de) under a Tomcat server I made a servlet that is supposed to run after the user types in some data. But I get an error message

maybe i did somthing wrong in the web.xml file when initializing the servlet?

<servlet>
     <servlet-name>PaliServlet</servlet-name>
     <servlet-class>PaliServlet</servlet-class>
</servlet>

<servlet-mapping>
   <servlet-name>PaliServlet</servlet-name>
   <url-pattern>/PaliServlet</url-pattern>
</servlet-mapping>

the servlet is in the folder where (I guess) it should be, /home/palibacs1/appservers/apache-tomcat-8.0.37/webapps/PaliServlet.class

Thanks in advance

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
bebe böbe
  • 11
  • 5
  • What error message do you get? Any stacktrace? – Roman Puchkovskiy Aug 06 '17 at 18:39
  • Exception report message Error instantiating servlet class webapps.PaliServlet description The server encountered an internal error that prevented it from fulfilling this request. exception javax.servlet.ServletException: Error instantiating servlet class webapps.PaliServlet org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) – bebe böbe Aug 06 '17 at 18:53
  • That's not sufficient, there is more of it than that. There is a 'caused by' exception further down. – user207421 Aug 07 '17 at 00:10
  • Ok, one of the problems was seemingly that i got at home Java 1.7 and the server was 1.8. - The sytem administrator fixed everything: "switched your JDK to 1.8 In conf/server.xml I set Paliba as default application I created simple /webapps/Paliba/WEB-INF/web.xml where URL is mapped to servlet class" – bebe böbe Aug 07 '17 at 20:35

2 Answers2

0

You need to give the class path of your servlet relative to your source folder in the servlet-class field.

Lets say your PaliServlet class is located inside Servlets folder in java folder marked as source folder. Then you need to give :

  <servlet>
     <servlet-name>PaliServlet</servlet-name>
     <servlet-class>Servlets.PaliServlet</servlet-class>
  </servlet>

  <servlet-mapping>
     <servlet-name>PaliServlet</servlet-name>
      <url-pattern>/PaliServlet</url-pattern>
  </servlet-mapping>
sourabh1024
  • 647
  • 5
  • 15
  • Thanks for the answer. The "webapps" folder, which contains the servlet, is the folder where Tomcat is looking for servlets in the first place (if i got it right), so it is not contained in an extra forlder inside webapps, it is directly in the "source folder" webapps. – bebe böbe Aug 06 '17 at 18:47
  • I did as you told and amended the path to: webapps.PaliServlet, then I got a different error message: Exception report message Error instantiating servlet class webapps.PaliServlet description The server encountered an internal error that prevented it from fulfilling this request. exception javax.servlet.ServletException: Error instantiating servlet class webapps.PaliServlet org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) etc. – bebe böbe Aug 06 '17 at 18:51
  • Can you give the complete error stack trace ? – sourabh1024 Aug 06 '17 at 18:59
  • now the message is simply : HTTP Status 404 - type Status report message description The requested resource is not available. - You can check it if you visit the website Palibacsi.de and type in 2 random answers. – bebe böbe Aug 06 '17 at 19:03
  • Can you give the resource path . i.e folders structure. It seems your path of servlet is still incorrect. – sourabh1024 Aug 06 '17 at 19:14
  • the main folder is "/home/palibacs1". This has several folders. Tomcat is in appservers/apache-tomcat-8.0.37. This has a webapps folder, the PaliServlet.class file is there. If there is an html command to print the folder structure on the screen, i can put it on the html site of my domain... – bebe böbe Aug 06 '17 at 19:16
  • Try adding your servlet class in /home/palibacs1/. And then give home.palibacs1.PaliServelet as servelt-class – sourabh1024 Aug 06 '17 at 19:24
  • Ok, I have tried that as you wrote, but i get the same error message. – bebe böbe Aug 06 '17 at 19:31
0

Your servlet class PaliServlet should have in /home/palibacs1/appservers/apache-tomcat-8.0.37/webapps/{Your_Project_Name}/WEB-INF/classes directory.

atiqkhaled
  • 386
  • 4
  • 19
  • Thanks, I have tried your solution, but I get the same error message: java.lang.ClassNotFoundException: home.palibacs1.appservers.apache-tomcat-8.0.37.webapps.Paliba.WEB-INF.classes.PaliServlet – bebe böbe Aug 06 '17 at 20:56
  • What abt your web.xml servlet-class path? – atiqkhaled Aug 06 '17 at 20:58
  • it is home.palibacs1.appservers.apache-tomcat-8.0.37.webapps.Paliba.WEB-INF.classes.PaliServlet – bebe böbe Aug 06 '17 at 21:03
  • make it like this `PaliSer‌​vlet` . Hope it works then. – atiqkhaled Aug 06 '17 at 21:07
  • thanks - no, it still does not find the class, even if I write only "PaliServlet" in the class path as you suggested. - I will try to get someone look at it next week IRL on my computer, and write the solution here, which has to be sg pretty obvious thing which i overlooked. – bebe böbe Aug 06 '17 at 21:14
  • ok..can you restart your tomcat server and check again. Make sure configuration is same as i mentioned. – atiqkhaled Aug 06 '17 at 22:01
  • ok, thanks. Btw. the project's name is Paliba, and now its not indicated in the class path, but even when I put it in the class path it did not find the servlet – bebe böbe Aug 06 '17 at 22:06