헤르메스 LIFE

[Eclipse] Eclipse WTP의 사용 1 본문

장난감들

[Eclipse] Eclipse WTP의 사용 1

헤르메스의날개 2010. 8. 12. 15:21
728x90

Eclipse WTP : http://www.eclipse.org/webtools/index.php

Eclipse의 한부분으로 Web과 Java EE Application 개발을 위한 Eclipse Flatform을 만들고자
Web Tools Platform (WTP) Project가 진행되었습니다. 현재 2007년09월26일 2.0.1버젼이 Release되었군요.
2007년06월26일 2.0버젼의 Bug들이 많이 Fix된 모양이네요.

 Eclipse WTP에는 Eclipse Europa 3.3 버젼이 포함되어있습니다.

Eclipse Europa 3.3 버젼은 기본적으로 Java 5.x 버젼이상이 설치되어 있어야 한다는군요.

Web Tools Platform All-In-One Packages 를 다운받으세요.
다운로드 : http://download.eclipse.org/webtools/downloads/

Apache Tomcat 다운로드 : http://jakarta.apache.org/tomcat/index.html( 기본적으로 5.5버젼이상 입니다. )

 1. 초기화면

2. JRE 셋팅

3. Server 추가 ( 기본적으로 Tomcat / JBoss 등을 지원합니다.)

4. 서버 Adapter 추가 ( New Server Runtime 에서 Down additional server adapters 클릭 )
   WebLogic Server / WebSphere Sever와 다른 서버도 추가시킬 수 있네요.
 

5. J2EE Perspective 추가







     \ Other 선택 ==>       

 

 













6. 신규프로젝트

 

7. 생성결과
 

 8. 신규 JSP 생성

소스

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<jsp:useBean id='form' class='beans.CandidateForm' scope='request'>
 <jsp:setProperty name='form' property='*' />
</jsp:useBean>
<!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=EUC-KR">
<title>Insert title here</title>
<link href='resources/eclipseworld.css' rel='stylesheet' type='text/css'>

<script language='JavaScript'>
// Generate Random Password
arrayOfChars = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r",
"s","t","u","v","w","x","y","z");
function randomChar() {
 arrayIndex = Math.ceil(Math.random() * (arrayOfChars.length - 1));
 return arrayOfChars[arrayIndex];
}
function generatePassword() {
 var password = randomChar() + randomChar() + randomChar() + randomChar()+ Math.ceil(Math.random() * 100);
 document.myForm.password.value = password;
}
</script>

</head>
<body>

<p>

<p class='errorFont'>
<% String errorMsg = (String) request.getAttribute("validateerror");
if(errorMsg != null) { %> <%= errorMsg %> <% } %>
</p>
<form name='myForm' method='post' action='NewCandidate'>
Name: <input type='text' name='name' value='<%=form.getName()%>'
/> <br />
User Name: <input type='text' name='userName' value='<%=form.getUserName()%>' /> <br />
Password: <input type='text' name='password' value='<%=form.getPassword()%>' />
<input type='button' value='Generate'onClick='javaScript:generatePassword()'/> <br /><br />
<input type='submit' value='Submit'/>
</form>
</body>
</html>

 

9. 신규 Form Class 생성

소스

package beans;

public class CandidateForm {
 private String name = "";
 private String userName = "";
 private String password = "";
 
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getUserName() {
  return userName;
 }
 public void setUserName(String userName) {
  this.userName = userName;
 }
 public String getPassword() {
  return password;
 }
 public void setPassword(String password) {
  this.password = password;
 }
}

 

10. 신규 Servlet Class 생성
 

소스

package servlets;

import java.io.IOException;

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

public class NewCandidateServlet extends HttpServlet {
 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  String name = req.getParameter("name");
  String userName = req.getParameter("userName");
  String password = req.getParameter("password");
  if (name.equals("") || userName.equals("") || password.equals("")) {
   req.setAttribute("validate-error", "Please fill in all fields");
   req.getRequestDispatcher("/addCandidate.jsp").forward(req, resp);
  } else {
   req.getRequestDispatcher("/candidateAdded.jsp").forward(req, resp);
  }
 }
}

 11. serialVersionUID Warning 제거하기
 

12. 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>EclipseWorld_WebApp</display-name>
 
  <servlet>
   <servlet-name>NewCandidate</servlet-name>
   <servlet-class>servlets.NewCandidateServlet</servlet-class>
  </servlet>
 
  <servlet-mapping>
   <servlet-name>NewCandidate</servlet-name>
   <url-pattern>/NewCandidate</url-pattern>
  </servlet-mapping>

 
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

 

13. 신규 CSS 파일 생성


14. WebContent 폴더 아래에 candidateAdded.jsp 생성 

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!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=EUC-KR">
<title>Registration Successful</title>
</head>
<body>
<jsp:useBean id='form' class='beans.CandidateForm' scope='request'>
<jsp:setProperty name='form' property='*' />
</jsp:useBean>
<a href="courses.jsp">Register for Courses</a>
<h1>Registration Successful</h1>
<p>Welcome <%=form.getName()%>. <br>
Your registration under user name <%=form.getUserName()%> was
successful.</p>
</body>

 

15. Server 설정


설정된 Server가 없음.

서버 설정

서버가 설정된 모습

 

728x90