Struts 1.1 安装、示例篇
- 作者:zhaozj
- 发表时间:2020-12-23 10:59
- 来源:未知
1. Struts 1.1 安装 安装Struts 1.1 比较简单。假设我们使用的是Tomcat 5.0,并且安装在D:/tomcat下。首先,请到http://jakarta.apache.org/struts/ 下载Struts 1.1,解压缩后,可以看到jakarta-struts-1.1目录,在这个目录下面,你可以看到这样一个目录:webapps.该目录下面有多个*.war,我们copy struts-blank.war 文件到D:/tomcat/webapps下,restart Tomcat,在Tomcat 的webapps下就会生成一个struts-blank空白Struts开发环境。另外,在你解压缩的目录下的webapps中 struts-example.war 是一个很好的struts学习教程,如果你想深入学习请访问http://jakarta.apache.org/struts 或者 下载 《Struts in Action》 E 文版。 2. 一个简单的例子 2.1 Logon.jsp
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ page contentType="text/html; charset=gb2312" %> <% /** * This page shows Logon interface. * Title: LOGON SYSTEM * Description: Logon Page * Copyright: Copyright (c) 2004 * Company: www.ewe.com.cn * @author bluesunny <hyjun2001@163.com> * @version 1.0 */ response.setHeader("Pragma","No-cache"); response.setHeader("Cache-Control","no-cache"); response.setDateHeader("Expires", 0); %> <html> <head> <title>Logon</title> </head> <body> <html:errors/> <html:form action="/Logon" focus="username"> username:<html:text property="username" size="25"/> password:<html:password property="password" size="25"/> <html:submit property=”submit”/> </html:form> </body> </html> |
package com.logon.app; import javax.servlet.http.*; import org.apache.struts.action.*; /** * This page shows LogonForm.java * Title: LOGON SYSTEM * Description: LogonForm Page * Copyright: Copyright (c) 2004 * Company: www.ewe.com.cn * @author bluesunny * @version 1.0 */ public class LogonForm extends ActionForm{ private String username; private String password; public LoginForm() { username = null; password = null; } public void setUsername(String username){ this.username = username; } public String getUsername() { return this.username; } public void setPassword(String password){ this.password = password; } public String getPassword(){ return this.password; } public void reset(ActionMapping mapping, HttpServletRequest request) { username = null; password = null; } } |