| |
技术文档>>JAVA>>新手入门>>基础入门>查看文档 |
|
| |
struts入门经验(一) |
|
| |
文章作者:未知 文章来源:水木森林 |
|
| |
查看:75次 录入:管理员--2007-11-17 |
|
| |
struts安装: 首先请到http://jakarta.apache.org/struts下载struts,建议使用release版,现在最高版本为1.1,下载后得到的是一个zip文件。 将zip包解开,可以看到这个目录: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属性、国际化的提示和消息等 一个实例: 一个用户注册系统,用户通过网页输入相关信息:注册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> 此jsp页面不同于普通的jsp页,因为它大量运用了taglib,这些taglib对初学者而言,可能难于掌握,可这却是struts的精华之一。灵活运用,将大大提高开发效率。
|
|
|
|
相关文档
|