Eclipse创建dynamic web Project

Dynamic web Project with eclipse

Pre-requestic i am assuming you have already installed jdk 1.5+ and eclipse (Euroepa,Ganeymede,Galideo)  if not please visit first How to Install/Configure Eclipse

and Tomcat is installed already , if you are not aware about Tomcat insallation please refer How to install Tomcat

and Tomcat is Configured with eclipse  if not refer    How to configure Tomcat with Eclipse

Step-1 Start Eclipse by clicking eclipse.exe or shortcut and after select workspace you will get the eclipse home and then select  File->New->Dynamic Web project to create Dynamic Web Project as shown below

Step-2   Enter Project  name and click finish as shown below.

Step-3 after clicking finish button , you will get next window  as shown below.

Step-4 now  Select window->show view->navigator to change view as shown below.

Step-5 now your project browser window  looks as shown below.

Step-6  To create new Servlet Right Click on src folder new->other as shown below



Step-7   Select Servlet in Web Category as shown below


Step-8    Type Servlet Name eg: LoginServlet and java package  as web and click next

Step-9 Change  URL Mappings by double clicking on that as shown below, i am using /login as url-pattern as shown below.


Step-10  Change the LoginServlet  code as given below

package web;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginServlet extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

response.setContentType(“text/html”);
PrintWriter out=response.getWriter();

out.println(“<h1>Welcome in Dynamic Project with Servlets </h1>”);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}

}


Step-11      open web.xml and select source tab as shown below



Step-12  now right click on server(tomcat) added in servers tab and select Add and Remove as shown below


Step-13 add delhi project  by clicking  Add Button  as shown below


Step-14  To Run Servlet      Right Click on LoginServlet -> Run As -> Run on Server


Step-15   click finish button as shown below.


Step-16  and you will get Output in Browser Window.


转载自:http://javateacher.co.in/eclipse/dynamic-web-project-with-eclipse/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值