• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mission accomplished.. thanks everyone...

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not able to generate class file for the servlet java codes. I am able to do all the other normal java stuff. My tomcat is in F directory and its functioning well as well.

This is my code

package classes;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class calci extends HttpServlet
{

public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {

int num1=Integer.parseInt(req.getParameter("N1"));
int num2=Integer.parseInt(req.getParameter("N2"));

res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println(num1+num2);
}
}

 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What error you are facing?
 
karthick Soundararaj
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vinod K Singh wrote:What error you are facing?



The error i get is
package javax.servlet.* does not exist.
package javax.servlet.http.* does not exist.



The tomcat location is F:/tomcat

My OS is in C drive,,,

Can path be a problem?

 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tomcat's JAR files are not in your classpath. Check this FAQ.
 
karthick Soundararaj
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got my previous problem solved.. thanks for the reply.. now a new problem has come...

This is the error i get in the browser

STATUS REPORT 500
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Error allocating a servlet instance
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Unknown Source)
root cause

java.lang.NoClassDefFoundError: calci (wrong name: classes/calci)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1876)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:889)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1353)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Unknown Source)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.



the following is my source code

Calculator.html

<html>
<head>
<title> Calculator</title>
</head>

<body>

<form method="POST" action="calcul.do">
<center><font type="monotype corsiva" size=15>
<italics>Calculator</italic>
</font>
<br><br><br><br>
Number 1: <input name="N1" type=text> <br><br>
Number 2: <input name="N2" type=text> <br><br>
<input type="Submit"></center>
</form></body>
<html>

web.xml

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<servlet>
<servlet-name>Ch3 Beer </servlet-name>
<servlet-class>calci</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Ch3 Beer </servlet-name>
<url-pattern>/calcul.do</url-pattern>
</servlet-mapping>

</web-app>


calci.java (no compilation error/warnings)

package classes;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class calci extends HttpServlet
{

public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {

int num1=Integer.parseInt(req.getParameter("N1"));
int num2=Integer.parseInt(req.getParameter("N2"));

res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println(num1+num2);
}
}

My deployment structure is:

F:\Tomcat\webapps\Calculator\calculator.html
F:\Tomcat\webapps\Calculator\WEB-INF\web.xml
F:\Tomcat\webapps\Calculator\WEB-INF\classes\calci.java

Frustrated yet determined.. please do help...


 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you could see in the error stack trace, its saying java.lang.NoClassDefFoundError: calci (wrong name: classes/calci)

And if you see web.xml you have defined the servlet class as :


Which should be


Besides the class name should start with a Capital letter.
 
karthick Soundararaj
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mohamed Inayath wrote:If you could see in the error stack trace, its saying java.lang.NoClassDefFoundError: calci (wrong name: classes/calci)

And if you see web.xml you have defined the servlet class as :


Which should be


Besides the class name should start with a Capital letter.



Changed both

now the error is

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Wrapper cannot find servlet class classes.Calci or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Unknown Source)
root cause

java.lang.ClassNotFoundException: classes.Calci
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1386)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Unknown Source)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.

Apache Tomcat/5.5.27



calculator.html --> No changes

Calci.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Calci extends HttpServlet
{

public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {

int num1=Integer.parseInt(req.getParameter("N1"));
int num2=Integer.parseInt(req.getParameter("N2"));

res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println(num1+num2);
}
}

web.xml

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<servlet>
<servlet-name>Ch3 Beer </servlet-name>
<servlet-class>classes.Calci</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Ch3 Beer </servlet-name>
<url-pattern>/calcul.do</url-pattern>
</servlet-mapping>

</web-app>

No changes made to the location

Hitting my keys with atmost desparation



 
karthick Soundararaj
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot everyone.. The only error was the fact that class name was in lowercase rather than Sentence case. The path name is just Calci not classes.Calci

 
Mohamed Inayath
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good.

But your earlier attachment wrt the calci.java says a package definition : classes.

This time I believe you have removed that.
 
karthick Soundararaj
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mohamed Inayath wrote:Good.

But your earlier attachment wrt the calci.java says a package definition : classes.

This time I believe you have removed that.



Thing is the statement package classes.Calci itself is wrong statements.. please do look at my location i have mentioned in one of my earlier posts..

Anyways your input regarding the Capital letter was helpful
 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic