通过MyEclipse使用Struts1.3弄个helloworld–7步走

没事,慢慢来,咱们使用Myeclipse来弄个helloworld,你就知道Struts1.3是很简单滴!~
1.file-new-web project 输入你的名字哦,比如:Struts1.3_01

 

2.选中项目,右键Myeclipse–add struts cabilities

–默认选项就可以。

看看生成的web.xml文件代码:
———————————————————————-

action
org.apache.struts.action.ActionServlet

config /WEB-INF/struts-config.xml

debug 3

detail 3
0

action
*.do

index.jsp

———————————————————————–
这个配置是说把后缀是.do 的请求交给struts来处理。

3.新建一个class继承action

4.在这个类里面重写execute方法

5.输入相关的代码:

———————————————————————————————–

package com.gagaj2ee.sanwen;

import java.io.PrintWriter;

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

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class HelloWorld extends Action {

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
PrintWriter out=response.getWriter();
out.println(“hello world”);
return null;
}

}

——————————————————————————————–

6.在struts的配置文件中加入部署的代码:

————————————————————————————————

<?xml version=”1.0″ encoding=”UTF-8″?>
< !DOCTYPE struts-config PUBLIC “-//Apache Software Foundation//DTD Struts Configuration 1.2//EN” “http://struts.apache.org/dtds/struts-config_1_2.dtd“>

<struts-config>
<data-sources />
<form-beans />
<global-exceptions />
<global-forwards />
<action-mappings>
<action path=”/hello” type=”com.gagaj2ee.sanwen.HelloWorld”></action>
</action-mappings>
<message-resources parameter=”com.yourcompany.struts.ApplicationResources” />
< /struts-config>

———————————————————————————————————————-

7.在浏览器打开,输入你的访问地址,看看效果:

共有 0 条评论

Top