1.如何安装struts:
首先到http://jakarta.apache.org/struts下载struts,建议使用release版,现在最高版本为1.2.6,有多种os版本(windows,linus...),下载后解压开来,可以看到这个目录:lib和webapps,webapps下有一些war文件。 假设你的tomcat装在c:\tomcat下,则将那些war文件拷贝到c:\tomcat\webapps,重新启动tomcat即可。打开浏览器,在地址栏中输入:http://localhost:8080/struts-example/index.jsp,若能见到“powered by struts”的深蓝色图标,即说明成功了。这是struts自带的一个例子,附有详细的说明文档,可以做为初学者的入门教程。另外,struts还提供了一系统实用对象:xml处理、通过java reflection apis自动处理javabeans属性、国际化的提示和消息等
2.练习做一个实例:
一个用户注册系统,用户通过网页输入相关信息:注册id号,密码,email,若注册成功,则返回成功提示信息,反之出现注册失败提示信息。
项目建立:
正式开发前,需要在tocmat(我的tomcat装在c:\tomcat)中建立此项目。比较快的一种建立方式为:在c:\tomcat\webapps下新建目录test,再将c:\tomcat\webapps\struts-example下的web-inf目录拷贝到test目录下,然后将test\web-inf下的src和classes目录清空,以及struts-config.xml文件中内容清空即可。这样,我们需要的struts类包及相关的配置文件就都齐了。
开发时,将jsp文件放在test目录下,java原文件放在test\web-inf\src下,编译后的类文件放在test\web-inf\classes下。
注册页面:reguser.jsp
<%@ page contenttype="text/html;charset=utf-8" language="java"
%>
<%@ taglib uri="/web-inf/struts-bean.tld" prefix="bean"
%>
<%@ taglib uri="/web-inf/struts-html.tld" prefix="html"
%>
<html:html locale="true">
<head>
<title>reguser</title>
<html:base/>
</head>
<body bgcolor="white">
<html:errors/>
<html:form action="/reguseraction" focus="logname">
<table border="0" width="100%">
<tr>
<th align="right">
logname:
</th>
<td align="left">
<html:text property="logname" size="20" maxlength="20"/>
</td>
</tr>
<tr>
<th align="right">
password:
</th>
<td align="left">
<html:password property="password" size="20" maxlength="20"/>
</td>
</tr>
<tr>
<th align="right">
e-mail:
</th>
<td align="left">
<html:password property="email" size="30" maxlength="50"/>
</td>
</tr>
<tr>
<td align="right">
<html:submit property="submit" value="submit"/>
</td>
<td align="left">
<html:reset/>
</td>
</tr>
</table>
</html:form>
</body>
</html:html>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器