File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Mission accomplished.. thanks everyone... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Mission accomplished.. thanks everyone... " Watch "Mission accomplished.. thanks everyone... " New topic
Author

Mission accomplished.. thanks everyone...

karthick Soundararaj
Greenhorn

Joined: Mar 09, 2009
Posts: 26
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);
}
}


A java addict
Vinod K Singh
Ranch Hand

Joined: Sep 30, 2008
Posts: 198
What error you are facing?


My Blog
karthick Soundararaj
Greenhorn

Joined: Mar 09, 2009
Posts: 26
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?

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Tomcat's JAR files are not in your classpath. Check this FAQ.


[My Blog]
All roads lead to JavaRanch
karthick Soundararaj
Greenhorn

Joined: Mar 09, 2009
Posts: 26
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...


Mohamed Inayath
Ranch Hand

Joined: Nov 22, 2004
Posts: 124
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

Joined: Mar 09, 2009
Posts: 26
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

Joined: Mar 09, 2009
Posts: 26
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

Joined: Nov 22, 2004
Posts: 124
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

Joined: Mar 09, 2009
Posts: 26
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Mission accomplished.. thanks everyone...