« | August 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | | | | | |
|
统计 |
blog名称:小雨 日志总数:262 评论数量:1273 留言数量:15 访问次数:4667410 建立时间:2005年1月8日 |
| 
|
W3CHINA Blog首页 管理页面 写新日志 退出
[知识积累]我的第一个struts |
小雨 发表于 2007/12/2 12:14:20 |
环境 tomcat5.5 ,jdk1.5 ,struts1.3.8
1 index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<!-- :TODO: It would be interesting to try this with frames and modules --><html><head> <title>RegUser</title></head> <body bgcolor="white"> <html:form action="/RegUser" 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>
2 RegUserAction
package org.cjea.Struts.example;
import javax.servlet.http.*; import org.apache.struts.action.*;
public final class RegUserAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm actionform, HttpServletRequest req, HttpServletResponse res) { RegUserForm form = (RegUserForm)actionform; String title = form.getLogName();String password = form.getPassWord();String email = form.getEmail(); if(title.equals("email"))return (mapping.findForward("success"));elsereturn (mapping.findForward("fails"));} }
3 RegUserForm
package org.cjea.Struts.example;import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping;
public final class RegUserForm extends ActionForm{
private String logname; private String password; private String email;
public RegUserForm(){ logname = null; password = null; email = null; }
public String getLogName() { return this.logname; } public void setLogName(String logname) { this.logname = logname; } public void setPassWord(String password) { this.password = password; } public String getPassWord() { return this.password; } public void setEmail(String email) { this.email = email; } public String getEmail() { return this.email; }
public void reset(ActionMapping mapping, HttpServletRequest request) { logname = null; password = null; email = null; } }
4 truts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?><!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.-->
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans> <form-bean name="simpleForm" type="org.cjea.Struts.example.RegUserForm"/> </form-beans> <action-mappings> <action path="/RegUser" type="org.cjea.Struts.example.RegUserAction" name="simpleForm" scope="request" validate="false"> <forward name="success" path="/html-good.jsp"/> <forward name="fails" path="/html-error.jsp"/> </action> </action-mappings>
<message-resources parameter="org.apache.struts.webapp.el.exercise.ApplicationResources" null="false"/>
</struts-config>
|
阅读全文(3356) | 回复(1) | 编辑 | 精华 |
回复:我的第一个struts |
aa(游客)发表评论于2007/12/2 21:22:18 | http://zol.zhuaxia.com/item/576762965/?logId=207
|
个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除 |
» 1 »
|