Java

Moderators: zibadian
Number of threads: 7832
Number of posts: 18231

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
servlet beginner confused Posted by anarelle on 26 Feb 2012 at 7:17 AM
I need to call a servlet from an HTML file, but I can't get my servlet to work outside the Eclipse IDE. Something must be wrong with my paths, but I don't know what.
I'm using Tomcat 7.0.

This is my servlet class:
package myapp;
public class HelloServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
StringBuffer sb = new StringBuffer();
sb.append("<html><body bgcolor=pink text=black>");
sb.append("<h1 align=center>Hello World!</h1>");
sb.append("<body></html>");
out.println(sb);
}
}

I also have this web.xml file:
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>myapp.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>

And my HTML file has a simple form like this:
<FORM METHOD=GET ACTION="HelloServlet">
<INPUT TYPE=SUBMIT>


Then, in my C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps folder I created a "test" folder where I placed my index.html file and a WEB-INF folder with the web.xml file and a sub-folder called "classes", where I placed HelloServlet.java and HelloServlet.class.
I also set environment variables in my windows 7 system: CATALINA_HOME with value C:\Program Files\Apache Software Foundation\Tomcat 7.0 and CLASSPATH with value %CLASSPATH%;%CATALINA_HOME%\common\lib\servlet-api.jar;.

With all of this, I start tomcat, open index.html and click on the submit button. All I get is a "Firefox can't find the file at /C:/Program Files/Apache Software Foundation/Tomcat 7.0/webapps/test/HelloServlet" error message.
What kind of newbie mistake am I making?

Thanks!!!
Report
Re: servlet beginner confused Posted by emime on 16 Mar 2012 at 4:37 AM
i will recomand to use jsp instead of usign servlets..it is better this way, and then u can call them through javascript with the xmlhttprequest search on the internet check this http://www.countcode.com
Report
Re: servlet beginner confused Posted by emime on 16 Mar 2012 at 4:39 AM
i will recomand to use jsp instead of usign servlets..it is better this way, and then u can call them through javascript with the xmlhttprequest search on the internet check this http://www.countcode.com
Report
Re: servlet beginner confused Posted by emime on 16 Mar 2012 at 4:42 AM
i will recomand to use jsp instead of usign servlets..it is better this way, and then u can call them through javascript with the xmlhttprequest search on the internet check this http://www.countcode.com



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.