---
title: "easyjweb初试--简单的say hello示例"
author: "lovethisworld"
date: "2010-08-05T10:03:33Z"
tags: ["Servlet", "Tomcat", "Web", "WebForm", "XML"]
categories: ["编程语言"]
slug: "easyjweb-say-hello"
draft: false
lastmod: "2010-08-05T13:37:48Z"
id: 729487
url: "https://lovethisworld.iteye.com/blog/729487"
---

**1. 下载EasyJWeb**

EasyJWeb作为一个开源项目，我们首先来看看与其相关的资源：

官方网站：[http://www.easyjf.com/easyjweb](http://www.easyjf.com/easyjweb)

EasyJWeb1.3下载：[http://www.easyjf.com/easyjweb/easyjweb-1.3-beta-all.zip](http://www.easyjf.com/easyjweb/easyjweb-1.3-beta-all.zip)

**2.新建项目**

新建一个名为hello的web工程，我们要实现功能就是让用户输入姓名，然后返回对用户的问候。解压下载好EasyJWeb的项目包，项目所需的jar包均在lib目录下，提取easyjweb-core-1.3.jar以及required目录下的所有jar包，加入到hello工程的lib目录下，此时我们便可以着手开发了。

**3. 开发一个Action**

建立com.easyjweb.action包并在包中新建HelloAction.java文件，内容如下：

```
package com.easyjweb.action;
 
import com.easyjf.web.IWebAction;
import com.easyjf.web.Module;
import com.easyjf.web.Page;
import com.easyjf.web.WebForm;
 
public class HelloAction implements IWebAction {
 
    public Page execute(WebForm form, Module module) throws Exception {
           String name = (String) form.get("name");
           if(name == null)
                  name = "亲爱的用户";
           form.addResult("msg", name + ",你好，欢迎来到easyJWeb的世界！");
           return new Page("/hello.html");
    }
}
```

 

 

**4.编辑页面**

在WEB-INF目录下新建views目录，并在目录下新建hello.html,内容如下：

```
<!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>第一个easyJWeb页面</title>
</head>
<body>
<form action="hello.ejf" method="post">
    请输入姓名：<input type="text" name="name" value="$!name"/><br>
    <input type="submit" name="提交" />
</form>
    <br />$!msg
</body>
</html>
```

 

 

**5.配置web.xml**

还要配置web.xml文件，内容如下：

```
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
    metadata-complete="false" version="2.5">
 
    <servlet>
       <servlet-name>easyjf</servlet-name>
       <servlet-class>com.easyjf.web.ActionServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
       <servlet-name>easyjf</servlet-name>
       <url-pattern>*.ejf</url-pattern>
    </servlet-mapping>
 
    <filter>
       <filter-name>CharsetFilter</filter-name>
       <filter-class>com.easyjf.web.CharsetFilter</filter-class>
       <init-param>
           <param-name>encoding</param-name>
           <param-value>UTF-8</param-value>
       </init-param>
       <init-param>
           <param-name>ignore</param-name>
           <param-value>true</param-value>
       </init-param>
    </filter>
    <filter-mapping>
       <filter-name>CharsetFilter</filter-name>
       <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>
```

 

 

**6。运行**

现在hello项目工程如下图所示：

![](/upload/picture/pic/68726/c205cb49-469b-3555-8a80-35970378f312.bmp)&lt;!--\[endif]--&gt;

启动tomcat，运行该工程，输入[http://localhost:8080/hello/hello.ejf](http://localhost:8080/hello/hello.ejf)，截图如下

![](/upload/picture/pic/68728/f03a912e-e72a-3a39-8bf9-00ff6b982bc5.bmp)&lt;!--\[endif]--&gt;

在文本框中输入”童鞋”，点击提交：

![](/upload/picture/pic/68730/9b4fe0ce-92de-399c-9aef-f6d9d14bb6e3.bmp)&lt;!--\[endif]--&gt;

好了，一个简单的web工程就建立完成了。接下来我们来开发一个对用户信息的增删改查的web工程。