• Post Reply Bookmark Topic Watch Topic
  • New Topic

wants to know about servlets programming

 
sajid dayer
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i just learn core java
and i want to make web application
using servlets
its ok with my old jdk 6
or should download java ee sdk
for web application
i have download tomcat 6
and i am trying to make simple page using servlets
but its giving me error "request resource is not available"
what should do
i am not using any IDE.....
 
K. Tsang
Bartender
Posts: 3604
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are NOT using IDE then you first need to gather the Java EE jar files like servlet*.jar or jstl jars and such.

In your error, by "request" does it mean the HTTP servlet request?

Remember to include those jars in the classpath when you compile.
 
sajid dayer
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have already add servlt-asp.jar and jsp-asp.jar file for classpath
and when i compile my servlets programe is compile easily compile without error
so now also i need that jar files ?
 
Santhosh Muralidharan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume you deployed the war file in Tomcat. Please ensure to verify the jar files in Tomcat.
 
sajid dayer
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
war file means?
and already told i set classpath for jar file thats why i didn't get any error at compile time
 
Santhosh Muralidharan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May i know how you are accessing the servlet deployed in Tomcat?. Did you configure the servlet in web.xml?
 
sajid dayer
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Example extends HttpServlet
{
public void servise(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
res.setContentType("text/html");
try{
PrintWriter out=res.getWriter();
out.println("<html><head> <title> hi buddy</title></head>");
out.println("<body> i am impressed with you</body></html>");
}
catch(IOException e)
{

}

}
}
 
sajid dayer
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<web-app>

<servlet>
<servlet-name>Ex</servlet-name>
<servlet-class>Example</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Ex</servlet-name>
<url-pattern>/helloworld</url-pattern>
</servlet-mapping>

</web-app>
 
sajid dayer
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\Users\ac\Desktop\apache-tomcat-6.0.44\webapps\demo\WEB-INF\web.xml.txt
and this folder structure is look like this
and i m accessing like this
http://localhost:8080/demo/helloworld
and also try like this http://localhost:8080/helloworld
 
Santhosh Muralidharan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please follow this example to deploy your servlet in Tomcat.http://www.mkyong.com/servlet/a-simple-servlet-example-write-deploy-run/
 
Santhosh Muralidharan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sajid dayer wrote:C:\Users\ac\Desktop\apache-tomcat-6.0.44\webapps\demo\WEB-INF\web.xml.txt
and this folder structure is look like this
and i m accessing like this
http://localhost:8080/demo/helloworld
and also try like this http://localhost:8080/helloworld


Your web.xml looks like a txt file C:\Users\ac\Desktop\apache-tomcat-6.0.44\webapps\demo\WEB-INF\web.xml.txt
Please change to web.xml file and deploy in tomcat.
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, when you post code, make sure to UseCodeTags (<= click and read). It makes your code more readable and understandable to others.
From your code, looks like you are using the default package for your servlet, which is not a recommended practice.
Use proper package for your servlet and mention the same in web.xml.
Then in your servlet, you should not be overriding the service (not servise)method. Instead override and implement the doGet() and doPost() methods.
sajid dayer wrote:war file means?

Your servlet should be part of a war file to be deployed in Tomcat. You can deploy exploded war as well, but I would recommend war files for starters.
This old but mostly valid thread will be a useful read.
Hope this helps
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!