Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » tomcat + dynamic web project
tomcat + dynamic web project [message #685941] Mon, 20 June 2011 20:54 Go to next message
moaad Mising name is currently offline moaad Mising nameFriend
Messages: 7
Registered: June 2011
Junior Member
Hello everybody

I'm using Eclipse Helios IDE
I have created a Dynamic Web application called : "first_appli". However I've noticed that the structure of the Web application is little bit weird.
In fact, the folder "classes" which is usually a subfolder of WEB-INF does not exist. Instead the "*.class" files are in folder called build in the "first_appli" directory.
I made a simple program : a form.html which calls a servlet.java servlet

I started by creating the form.html which is the welcome page :

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>	Beer Form </title>
</head>
<body>
	<h1 align="center">Beer Selection Page</h1>
	<form method="post" action="/servlet">
		Select beer characteristics<p>
		Color:
		<select name="color" size="1">
			<option value="light"> light </option>
			<option value="amber"> amber </option>
			<option value="brown"> brown </option>
			<option value="dark"> dark </option>
		</select>
		<br><br>
		<center>
			<input type="submit">
		</center>
	</form>
</body>


the form calls a servlet :

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class servlet
 */
public class servlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request,	HttpServletResponse response)throws IOException, ServletException {
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println("Beer Selection Advice<br>");
		String c = request.getParameter("color");
		out.println("<br>Got beer color " + c);
	}
}


Finally, I edited the Deployment Descriptor web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>FirstServlet</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    <welcome-file>form.html</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <servlet-name>servlet_name</servlet-name>
    <servlet-class>servlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>servlet_name</servlet-name>
    <url-pattern>/servlet</url-pattern>
  </servlet-mapping>
    </web-app>



The servlet.java is in the default folder within src folder in the Java_Ressources folder.
Logically, the <servlet-name> tag point to the class file and not the source file ( correct me!!) . Therefore, the fact that the servlet.class is hidden in the build folder surely will matter.

In order to overcome this problem, I tried to create a "classes" subfolder in WEB-INF and put servlet.class in it ==> KO not working

I've put the servlet.class directly in the WEB-INF ==> KO still not working

COULD YOU PLEASE HELP, It's been 2 days since I'm stuck here

thanks in advance
Re: tomcat + dynamic web project [message #697238 is a reply to message #685941] Fri, 15 July 2011 21:28 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 2333
Registered: July 2009
Senior Member
Get out of the habit of using the default folder/package. Many use cases will outright fail. Put your Servlet class into a package.

As for the discrepancy between the /build and WEB-INF/classes folder, it's handled for you when you launch your application.


---
Nitin Dahyabhai
Eclipse WTP, IBM
Re: tomcat + dynamic web project [message #1153103 is a reply to message #697238] Thu, 24 October 2013 11:34 Go to previous message
suvarna deo is currently offline suvarna deoFriend
Messages: 11
Registered: August 2013
Junior Member
Your web.xml file also not correct. for ex ReadExcel.java is a servlet class.
<servlet>
<description></description>
<display-name>ReadExcel</display-name>
<servlet-name>ReadExcel</servlet-name>
<servlet-class>com.xx.excel.ReadExcel</servlet-class> // com.xx.excel is a package name.
</servlet>
<servlet-mapping>
<servlet-name>ReadExcel</servlet-name>
<url-pattern>/ReadExcel</url-pattern>
</servlet-mapping>
Previous Topic:Where is wtp-parent Maven project ?
Next Topic:How do overlays in org.eclipse.wst.common.component work
Goto Forum:
  


Current Time: Mon Nov 24 21:38:12 GMT 2014

Powered by FUDForum. Page generated in 0.01982 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software