您的位置:首页 > 其它

easyjweb初试--简单的say hello示例

2010-08-08 16:11 295 查看
 

1. 下载EasyJWeb

EasyJWeb作为一个开源项目,我们首先来看看与其相关的资源:
官方网站:http://www.easyjf.com/easyjweb
EasyJWeb1.3下载: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");
}
}
[/code]
 
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项目工程如下图所示:



启动tomcat,运行该工程,输入http://localhost:8080/hello/hello.ejf,截图如下



在文本框中输入”童鞋”,点击提交:



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

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息