Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set conf file file

 
maha devan
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi members I am Beginner in servlets

Actually I have written a small servlet. Compiled it and placed it inside the WEB-INF/classes folder.
I have also written the mapping in xml as follows
<servlet>
<servlet-name>
servletToJsp
</servlet-name>
<servlet-class>
ServletSample
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
servletToJsp
</servlet-name>
<url-pattern>
/servletToJsp
</url-pattern>
</servlet-mapping>

How to open it on Browser .At present I tried something like this
http://localhost:8080/sampleworks/ServletToJsp and got error
How could i do it..I am using Tomcat.

Anybody pls
Maha
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use following URL

http://localhost:8080/ServletToJsp
 
maha devan
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ali

I tried that URL I am getting error Like this

type Status report

message /ServletToJsp

description The requested resource (/ServletToJsp) is not available.

U see I even restarted Tomcat. As somebody told it will take effect only after restarting.

Maha
 
maha devan
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For more clarity
I am having a main folder samplworks inside webapps.
sampleworks/WEB-INF/classes/ServletSample.class
sampleworks/WEB-INF/web.xml

Thanks
maha
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry i have written the capital "S". Use http://localhost:8080/servletToJsp
It should work.
 
maha devan
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had tried the URL http://localhost:8080/servletToJsp
Same error is coming
But if I try
http://localhost:8080/sampleworks/servletToJsp
I am getting the error as follows

root cause

java.lang.IllegalAccessException: Class org.apache.catalina.core.StandardWrapper can not access a member of class ServletSample with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:57)

Thanks
Maha
 
maha devan
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am pasting my code over here

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
class ServletSample extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
{
response.setContentType("Text/html");
try
{
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<B> Hi ");
out.println("</html>");
out.println("</body>");
}
catch(IOException e)
{}
}
}

Thanks Maha
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In deployment descriptor you have used

<servlet-class>
ServletSample
</servlet-class>



Use full name of the class with package name. Like


Here instead of package_name write the package in which you have made the ServletSample Servlet.
May be this will work.
 
maha devan
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ali Thanks for that Now the servlet it tryig to open

But I get an Error like this

root cause
java.lang.IllegalAccessException: Class org.apache.catalina.core.StandardWrapper can not access a member of class ServletSample with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:57)
at java.lang.Class.newInstance0(Class.java:302)

Whats this error About.
I think I have posted my code also pls look over

Thanks
Maha
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make your servlet class as public.
 
maha devan
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ali
At last it worked
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic