• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to Run Servlet from past two days

 
deepak carter
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Iam new to servlet.I have installed the tomcat 6 and i am using jdk 1.6.This is my code for servlet

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

class MyPage extends HttpServlet
{
public void goGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
try
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("</html>"+
"<head><title>My Second Page</title></head>"+
"<body>chal ja yaar</body>"+
"</html>");
}
catch(Exception e)
{

}

}

}


my web.xml file is

<?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">

<servlet>
<servlet-name>Page</servlet-name>
<servlet-class>MyPage</servlet-class>
</servlet>

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

</web-app>

i have placed the class file in C:\Tomcat 6.0\webapps\MyFirstWebApp\WEB-INF\classes
and xml file in C:\Tomcat 6.0\webapps\MyFirstWebApp\WEB-INF


and using is path to run it

http://localhost:8080/MyFirstWebApp/Page BUT ITS GIVING ME AN ERROR

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 MyPage
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)

root cause

java.lang.IllegalAccessException: Class org.apache.catalina.core.StandardWrapper can not access a member of class MyPage with modifiers ""
sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
java.lang.Class.newInstance0(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.32 logs.




AN EARLY RESPONSE WOULD BE HIGHLY APPRECIATED AS I AM HAVING NIGHTMARE FROM THE PAST TWO DAYS DU TO THIS

thank you

 
Valery Lezhebokov
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to make class MyPage public, i.e.:

 
deepak carter
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I did that but still its not working
 
deepak carter
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a problem in tomcat or there is something wrong in my code
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem may be in your failure to put your servlet in a package and define that package in the web.xml class section.



This is a common beginner error.

If your class is not in a defined package this is called the "default" package. The JVM looks for default package classes in the "current" directory - in the servlet environment you have no control over the current directory.

See this FAQ entry on the invoker servlet - which early servlet container implementors liked to use, supposedly to make it easy for beginners - this was a really really bad idea.

So: ALL classes used in servlets should be in packages and compiled classes located accordingly.

Bill
 
Stefan Evans
Bartender
Pie
Posts: 1670
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet class not being in a package, while not good practice, shouldn't stop it working.

Do you get a different error message or the same?
Running on Tomcat 7 I got:

message: HTTP method GET is not supported by this URL
description: The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).


The issue is caused because you haven't declared a method:


I will admit to having to put the code into my IDE, and then use Eclipse's "override/implement" methods feature before I spotted the spelling mistake in your version.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:The servlet class not being in a package, while not good practice, shouldn't stop it working.

It might work -- it might not. It's hit or miss, and the first thing to eliminate as a possible source of problems.
 
balaramakrishna ramakrishna
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove concatenation in out.println method it is browser issue
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
balaramakrishna ramakrishna wrote:Remove concatenation in out.println method it is browser issue

Huh? That sounds like nonsense.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic