struts学习笔记
一、环境搭建
a) jdk:一些工具都是运行在此平台上的,有些工具自带了jdk。
http://java.sun.com/j2se/1.4.2/download.html
b) eclipse:java的ide开发工具。
http://www.eclipse.org
c) struts:struts开发工具包。
http://struts.apache.org/
d) tomcat:web服务器,用于测试、发布web应用程序。
http://jakarta.apache.org/tomcat/index.html
e) ant:基于java的构建工具。
http://ant.apache.org/
f) 几个常用的eclipse插件:
lomboz、xmlbuddy、checkstyle、tomcat、emf-sdo-runtime
二、配置开发环境
a) 设置环境变量
java_home、tomcat_home、ant_home
在path中添加%java_home%/bin、%tomcat_home%/bin、%ant_home%/bin
b) 配置lomboz插件
设置lomboz插件的“jkd tools.jar:”、“server definitions”选项
c) 配置tomcat插件
设置tomcat插件的“tomcat version”、“tomcat home”、“jvm settings”选项
其中“jvm settings”中指定的jre必须为jdk的路径
三、测试开发环境
a) 新建lomboz j2ee project项目,取名为test
b) 下一步,下一步
c) 在web modules中添加module,取名为mytest
d) 在targeted servers中选择添加web服务器,这里选择了apache tomcat v5.0.x
e) 完成后添加一source folder,取名为src
f) 设置test项目的输出路径为test/mytest/web-inf/classes
g) 打开lomboz j2ee view,deploy mytest
h) 启动tomcat,打开浏览器输入http://localhost:8080/mytest
i) 显示welcome
四、基于struts的helloworld
a) 将struts开发工具包lib目录下的*.jar文件拷贝到test/mytest/web-inf/lib目录下
b) 将struts开发工具包lib目录下的*.dtd、*.tld、*.xml文件拷贝到test/mytest/web-inf/目录下
c) 右键点击mytest,选择lomboz j2ee中的add web-inf/lib jars to classpath选项
d) 编辑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>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
e) 新建struts-config.xml文件,添加代码:
<?xml version="1.0" encoding="utf-8"?>
<!doctype struts-config system "struts-config_1_2.dtd">
<struts-config>
<action-mappings>
<action
path="/my"
forward="/helloworld.jsp"/>
</action-mappings>
<controller processorclass="org.apache.struts.action.requestprocessor"
contenttype="text/html"/>
</struts-config>
闽公网安备 35060202000074号