Today i downloaded Eclipse IDE and tried to do my first program.I created an HTML file and an servlet class.The HTML file will accept emp details and the servlet program will just Echo those details.When i run HTML file i am getting description: The requested resource (/JavaWebProject/servlet/EmpEchoServlet) is not available.
Below is the code.
//EmpEcho.html <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Echo emp details</title> </head> <body bgcolor=cyan text=blue> <h2>Enter emp details</h2> <form name=EMPFORM method=GET action='servlet/EmpEchoServlet'> Enter Employee Number <input type=text name=EMPNO size=15> <br><br> Enter Employee Name <input type=text name=ENAME size=25> <br><br> Enter Employee Job <input type=text name=JOB size=15> <br><br> <input type=Submit value='Send Data'> </form>
Please try to paste the code using "Code" tags so that it will make the code visible clearly without uncluttered.
Try setting your classpath for the project in eclipse as "WEB-INF/classes". You can do so by right clicking on the project and its "BuildPath" settings. In that case, it automatically places the .class files in the location where you set.
Moreover, eclipse as an IDE does NOT create the folder structure for you. And a J2EE application should adhere its structure as per Sun's suggestions and guidelines. The class files are retrieved from the web/application server from the "<ProjectRoot>/WEB-INF/classes" directory. Remember, the WEB-INF is case sensitive!
Please have a look at the image "7.3 Web Application Directory Structure" in this url for further understanding on this. Create a folder structure like this first and then create a project in eclipse based out of this structure.
Which servlet container / web server are you using?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
The main problem is in your HTML file. You've listed the form's action to be servlet/EmpEchoServlet. However, in your web.xml file, you've listed the url-pattern to be just /EmpEchoServlet. Try removing the servlet prefix in the HTML form's action attribute.
I'm assuming that you've got your servlet class file located in the com\test subdirectory structure below WEB-INF\classes directory.
Thank you Mark. I removed servlet in 'servlet/EmpEchoServlet' but still i am getting the same problem. I tried giving '/JavaWebProject/EmpEchoServlet' in my html file, surprise it worked. Thank you all for your suggestions.
subject: Doubt in servlet program using eclipse IDE