Eclipse的初次使用_原创

看到网上说eclipse要用许多插件,经过尝试后,用eclipse网站提供的插件可以满足大部分的要求,首先下载eclipse SDK,现在的版本为3.1.1,这个版本有中文补丁.解压后复制到相应目录即可.启动时如果没有找到JAVA虚拟机,可以在运行栏输入D:/eclipse/eclipse.exe -vm C:/j2sdk1.4.2_09/jre/bin/javaw.exe,JAVA环境版本为J2SE SDK 1.4.2,
第一个JAVA工程:
eclipse SDK可以直接开发JAVA Project,无需任何补丁.
新建一个JAVA Project工程,输入代码,
public class Test{
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  System.out.println( "Hello World!");
 }
}
运行之,此时会有一个对话窗,让你选择需要运行的类,找到Test类或输入Test开始执行,可以在下面的Problems看到编译错误,在Console看到运行结果.
J2EE工程:
J2EE Project包含Jsp/Servlet,Web Service,EJB等等,这时需要下载插件,可以到Help-->Software Updates下载.
Eclipse网站上的主要插件:
GEF
  Graphicl Editing Framework
EMF
  XML,XSD
JEM
  Java EMF Model
VE
  Visual Editor
WTP
  J2EE Standard Tool and Web Standard Tool
VE为可视化编辑,支持Swing和AWT.
J2EE需要下载的是EMF,JEM,WTP,WTP相当于Lomboz
准备好了插件后,还需要一个Web服务器,网上有TOMCAT或JBOSS,相当于Microsoft的IIS
TOMCAT支持Jsp/Servlet,JBOSS支持Jsp/Servlet和EJB,看你的需要.
在Eclipse中的server runtime environment添加TOMCAT或JBOSS
第一个JSP Project工程:
新建一个Dynamic Web Project工程,在WebContent下新建一个JSP文件:
TestPage.jsp代码
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
 <table border="1"> 
  <tr>
   <th>Header</th>
   <th>Value</th> 
  </tr> 
  <tr>  
   <td>user-agent</td>  
   <td><%= request.getAttribute("client.browser")%></td> 
  </tr>
 </table>
</body>
</html>
在JavaSource中新建一个Servlet
TestClass.java文件类
package test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * Servlet implementation class for Servlet: TestClass
 *
 */
 public class TestClass extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
    /* (non-Java-doc)
  * @see javax.servlet.http.HttpServlet#HttpServlet()
  */
 public TestClass() {
  super();
 }    
 
 /* (non-Java-doc)
  * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
  // TODO Auto-generated method stub
  String userAgent =  request.getHeader("user-agent");
  String clientBrowser =  "Not known!"; 
  if( userAgent != null)
   clientBrowser = userAgent;
  request.setAttribute("client.browser",clientBrowser );
  request.getRequestDispatcher("/TestPage.jsp").forward(request,response);
 }   
 
 /* (non-Java-doc)
  * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
  // TODO Auto-generated method stub
 }          
}
点击Run on Server
或浏览器中输入 Http://localhost:8080/TestClass
这是一个由Servlet访问JSP的简单例子.
可以在 http://www.objectlearn.com/index.jsp-->documentation看到更多
新手学习请多多指教.
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值