import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class getname extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void destroy() {
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
String name = null;
PrintWriter out = response.getWriter();
if(request.getParameter("txtname") != null) {
name = request.getParameter("txtname");
}
else {
name = "";
}
out.println("You have successfully made Ajax Call:" + name);
}
}
I compiled the code using the below line: -
C:\>javac -classpath "C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib
\servlet-api.jar" "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapp
s\tut\WEB-INF\classes\com\mmfsl\web\gettime.java"
This servlet compiled without any errors and generated class file also.
This is my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name> My Tutorials </display-name>
<servlet>
<servlet-name>gettime</servlet-name>
<servlet-class>com.mmfsl.web.gettime</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>gettime</servlet-name>
<url-pattern>/gettime.do</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>getname</servlet-name>
<servlet-class>com.mmfsl.web.getname</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>getname</servlet-name>
<url-pattern>/getname.do</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>Login.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>500</error-code>
</error-page>
</web-app>
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: Error instantiating servlet class com.mmfsl.web.getname
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:401)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:281)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1568)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.NoClassDefFoundError: com/mmfsl/web/getname (wrong name: getname)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClassCond(Unknown Source)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2778)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1139)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1633)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1511)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:401)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:281)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1568)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.2 logs.
Apache Tomcat/7.0.2
<big><u><b>Can any one help me what it is.</b></u></big>