MyEclipse中手工配置struts项目的方法及注意细节

本人经常用myeclipse开发工具进行web方面的开发,对于struts项目,以前基本上都用myeclipse自带的工具进行struts的添加。

具体方法步骤如下:

1、添加struts相关jar包

struts.jar

commons-logging.jar

commons-beanutils.jar

commons-digester.jar

commons-fileupload.jar

commons-validator.jar

jakarta-oro.jar

antlr.jar

将上面这些jar文件拷贝到项目lib目录

2、添加tld标签库文件

一共有五大标签库文件是:

struts-html.tld

struts-bean.tld

struts-logic.tld

struts-tiles.tld

struts-nested.tld

将以上文件拷贝到你的项目WEB-INF目录

3、添加struts核心配置文件:struts-config.xml

<?xmlversion="1.0"encoding="UTF-8"?>

<!DOCTYPEstruts-configPUBLIC"-//ApacheSoftwareFoundation//DTDStrutsConfiguration1.2//EN""http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>

<data-sources/>

<form-beans/>

<global-exceptions/>

<global-forwards/>

<action-mappings/>

<message-resourcesparameter=""/>

</struts-config>

4、在web.xml中添加ActionServlet配置:

struts对于所有的web请求都变成*.do,通过ActionServlet来统一处理。

web.xml文件中加入:

<servlet>

<servlet-name>action</servlet-name>

<servlet-class>

org.apache.struts.action.ActionServlet

</servlet-class>

<init-param>

<param-name>config</param-name>

<param-value>/WEB-INF/struts-config.xml</param-value>

</init-param>

<init-param>

<param-name>debug</param-name>

<param-value>3</param-value>

</init-param>

<init-param>

<param-name>detail</param-name>

<param-value>3</param-value>

</init-param>

<load-on-startup>0</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>action</servlet-name>

<url-pattern>*.do</url-pattern>

</servlet-mapping>

<jsp-config>

<taglib>

<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>

<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>

</taglib>

<taglib>

<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>

<taglib-location>/WEB-INF/struts-html.tld</taglib-location>

</taglib>

<taglib>

<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>

<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>

</taglib>

<taglib>

<taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>

<taglib-location>

/WEB-INF/struts-nested.tld

</taglib-location>

</taglib>

<taglib>

<taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>

<taglib-location>

/WEB-INF/struts-template.tld

</taglib-location>

</taglib>

<taglib>

<taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>

<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>

</taglib>

</jsp-config>

到此为止,手工配置struts完成。

但是,当打开struts-config.xml文件时发现出问题了,不能正常打开。抛出如下异常:

org.eclipse.ui.PartInitException:ProjectnewsjqisnotconfiguredasaMyEclipseWeb-StrutsProject.ThereforetheMyEclipseStrutsEditormaynotbeusedwithstruts-config.xml.ThedefaultXMLEditorhasbeenusedtoopenthefileinstead.

经过对比发现,在此项目的.property缺少了<nature>com.genuitec.eclipse.cross.easystruts.eclipse.easystrutsnature</nature>

对其进行编辑并添加该内容后,一切ok了。

相关推荐