struts代码

1.struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "
http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<struts-config>
  <data-sources >
    <data-source key="sql2000">
      <set-property property="minCount" value="1" />
      <set-property property="password" value="" />
      <set-property property="maxCount" value="5" />
      <set-property property="user" value="sa" />
      <set-property property="driverClass" value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />
      <set-property property="description" value="" />
      <set-property property="url" value="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs" />
      <set-property property="autoCommit" value="true" />
      <set-property property="readOnly" value="false" />
      <set-property property="loginTimeout" value="" />
    </data-source>

  </data-sources>

  <form-beans >
    <form-bean name="empForm" type="com.struts.form.EmpForm" />
    <form-bean name="dptForm" type="com.struts.form.DptForm" />
    <form-bean name="pageForm" type="com.struts.form.PageForm" />
    <form-bean name="loveForm" type="com.struts.form.LoveForm" />
   
   

  </form-beans>

  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action
      attribute="empForm"
      input="/addemp.jsp"
      name="empForm"
      path="/addEmp"
      type="com.struts.action.AddEmpAction"
      validate="false">
      <forward
        name="adderror"
        path="/adderror.jsp"
        redirect="true" />
      <forward
        name="addemp"
        path="/addemp.jsp"
        redirect="true"
        contextRelative="true" />
    </action>
    <action
      attribute="dptForm"
      input="/adddpt"
      name="dptForm"
      path="/addDpt"
      type="com.struts.action.AddDptAction"
      validate="false">
      <forward
        name="adderror"
        path="/addError.jsp"
        redirect="true" />
      <forward
        name="adddpt"
        path="/adddpt.jsp"
        contextRelative="true" />
    </action>
    <action
      path="/dispEmp"
      type="com.struts.action.DispEmpAction"
      validate="false">
      <forward name="delemp" path="/delEmp.do" />
      <forward
        name="dispemp"
        path="/dispemp.jsp"
        contextRelative="true" />
      <forward name="updateemp" path="/updateEmp.do" />
    </action>
    <action
      path="/dispDpt"
      type="com.struts.action.DispDptAction"
      validate="false">
      <forward
        name="dispdpt"
        path="/dispdpt.jsp"
        contextRelative="true" />
    </action>
    <action
      attribute="empForm"
      input="/updateemp.jsp"
      name="empForm"
      path="/updateEmp"
      type="com.struts.action.UpdateEmpAction"
      validate="false">
      <forward
        name="dispemp"
        path="/dispEmp.do"
        redirect="true" />
      <forward name="updateemp" path="/updateemp.jsp" />
    </action>
    <action
      path="/delEmp"
      type="com.struts.action.DelEmpAction"
      validate="false">
      <forward name="dispemp" path="/dispEmp.do" />
    </action>
    <action
      attribute="dptForm"
      input="/updatedpt.jsp"
      name="dptForm"
      path="/updateDpt"
      type="com.struts.action.UpdateDptAction"
      validate="false">
      <forward name="updatedpt" path="/updatedpt.jsp" />
      <forward name="dispDpt" path="/dispDpt.do" />
      <forward name="adderror" path="/addError.jsp" />
    </action>
    <action
      path="/delDpt"
      type="com.struts.action.DelDptAction"
      validate="false">
      <forward name="updatedpt" path="/updatedpt.jsp" />
      <forward name="dispdpt" path="/dispDpt.do" />
    </action>
 
  </action-mappings>
  <message-resources parameter="com.struts.ApplicationResources" />
  <plug-in className="com.plug.DaoPlug"></plug-in>
</struts-config>


2.web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="
http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <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>
    <init-param>
      <param-name>debug</param-name>
      <param-value>3</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>3</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
 
  <servlet>
    <description>This is the description of my J2EE component</description>
    <display-name>This is the display name of my J2EE component</display-name>
    <servlet-name>Filt</servlet-name>
    <servlet-class>com.filt.Filt</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Filt</servlet-name>
    <url-pattern>/filt</url-pattern>
  </servlet-mapping>
 
</web-app>


3.Action.java
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.struts.action;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.struts.form.EmpForm;
import com.business.*;
/**
 * MyEclipse Struts
 * Creation date: 10-21-2007
 *
 * XDoclet definition:
 * @struts.action path="/addEmp" name="empForm" input="/addemp.jsp" scope="request"
 * @struts.action-forward name="addemp" path="/addemp.jsp" contextRelative="true"
 */
public class AddEmpAction extends Action {
 /*
  * Generated Methods
  */

 /**
  * Method execute
  * @param mapping
  * @param form
  * @param request
  * @param response
  * @return ActionForward
  */
 public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {
  EmpForm empForm = (EmpForm) form;// TODO Auto-generated method stub
  EmpBusiness em = (EmpBusiness) servlet.getServletContext().getAttribute("em");
  if(em.empsave(empForm)){
   return mapping.findForward("addemp");
  }else{   
   return mapping.findForward("addEroor");
  }
 }
}

4.EmpForm.java
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.struts.form;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

/**
 * MyEclipse Struts
 * Creation date: 10-21-2007
 *
 * XDoclet definition:
 * @struts.form name="empForm"
 */
public class EmpForm extends ActionForm {
 /*
  * Generated fields
  */

 /** email property */
 private String email;

 /** eaddress property */
 private String eaddress;

 /** ename property */
 private String ename;

 /** eid property */
 private String eid;
 private String did;
 private String [] loveid;

 /*
  * Generated Methods
  */

 /**
  * Method validate
  * @param mapping
  * @param request
  * @return ActionErrors
  */
 public ActionErrors validate(ActionMapping mapping,
   HttpServletRequest request) {
  // TODO Auto-generated method stub
  return null;
 }

 /**
  * Method reset
  * @param mapping
  * @param request
  */
 public void reset(ActionMapping mapping, HttpServletRequest request) {
  // TODO Auto-generated method stub
 }

 /**
  * Returns the email.
  * @return String
  */
 public String getEmail() {
  return email;
 }

 /**
  * Set the email.
  * @param email The email to set
  */
 public void setEmail(String email) {
  this.email = email;
 }

 /**
  * Returns the eaddress.
  * @return String
  */
 public String getEaddress() {
  return eaddress;
 }

 /**
  * Set the eaddress.
  * @param eaddress The eaddress to set
  */
 public void setEaddress(String eaddress) {
  this.eaddress = eaddress;
 }

 /**
  * Returns the ename.
  * @return String
  */
 public String getEname() {
  return ename;
 }

 /**
  * Set the ename.
  * @param ename The ename to set
  */
 public void setEname(String ename) {
  this.ename = ename;
 }

 /**
  * Returns the eid.
  * @return String
  */
 public String getEid() {
  return eid;
 }

 /**
  * Set the eid.
  * @param eid The eid to set
  */
 public void setEid(String eid) {
  this.eid = eid;
 }

 public String getDid() {
  return did;
 }

 public void setDid(String did) {
  this.did = did;
 }

 public String[] getLoveid() {
  return loveid;
 }

 public void setLoveid(String[] loveid) {
  this.loveid = loveid;
 }
}

5.add.jsp
<%@ page language="java" pageEncoding="UTF-8"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="
http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="
http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="
http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="
http://jakarta.apache.org/struts/tags-template" prefix="template" %>
<%@ taglib uri="
http://jakarta.apache.org/struts/tags-nested" prefix="nested" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html locale="true">
  <head>
    <html:base />
   
    <title>addemp.jsp</title>

 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->

  </head>
 
  <body>
  <br>
  <p align="center">添加员工</p>
  <html:form action="addEmp.do">
  <table width="296" height="132" border="1" align="center">
    <tr>
      <td width="79">姓名:</td>
      <td width="201"><html:text property="ename"/></td>
    </tr>
    <tr>
      <td>地址:</td>
      <td><html:text property="eaddress"/></td>
    </tr>
    <tr>
      <td>email:</td>
      <td><html:text property="email"/></td>
    </tr>
    <tr>
      <td>爱好:</td>
      <td><logic:iterate id="lo" name="love">
        <html:multibox property="loveid">
         <bean:write name="lo" property="lid"/>
        </html:multibox>
        <bean:write name="lo" property="lname"/>
       </logic:iterate></td>
    </tr>
    <tr>
      <td>部门:</td>
      <td>
      <html:select property="did">
      <html:optionsCollection label="dname" name="op" value="did" />
      </html:select>
      </td>
    </tr>
    <tr>
      <td colspan="2" align="center">
    <html:submit value="提交"></html:submit> 
    </td>
    </tr>
   
  </table>
  <a href="dispEmp.do?cp=1">查看员工</a>
  </html:form>
  </body>
</html:html>


6.list.jsp

<%@ page language="java" pageEncoding="UTF-8"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="
http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="
http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="
http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="
http://jakarta.apache.org/struts/tags-template" prefix="template" %>
<%@ taglib uri="
http://jakarta.apache.org/struts/tags-nested" prefix="nested" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html locale="true">
  <head>
    <html:base />
   
    <title>dispemp.jsp</title>

 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->

  </head>
 
  <body>
  <bean:define id="vt" name="pg" property="pagedata"></bean:define>
    <br>
    <table width="543" height="47" border="1" align="center">
      <tr>
        <td width="" height="22" align="center">员工编号</td>
        <td width="" align="center">姓名</td>
        <td width="" align="center">地址</td>
        <td width="" align="center">email</td>
        <td width="" align="center">部门</td>
        <td width="" align="center">操作</td>
      </tr>
 <logic:iterate id="emp" name="vt">
      <tr>
        <td>
         <bean:write name="emp" property="eid"/>
        </td>
        <td><bean:write name="emp" property="ename"/></td>
        <td><bean:write name="emp" property="eaddress"/></td>
        <td><bean:write name="emp" property="email"/></td>
        <td><bean:write name="emp" property="did"/></td>
        <td width="" align="center"><a href="updateEmp.do?id=<bean:write name="emp" property="eid"/>">修改</a>&nbsp;&nbsp;<a href="delEmp.do?id=<bean:write name="emp" property="eid"/>">删除</a></td>
      </tr>
 </logic:iterate>
    </table>
    <p align="center"><a href="dispEmp.do">首页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="dispEmp.do?cp=${pg.currentpage-1}">上一页</a>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; <a href="dispEmp.do?cp=${pg.currentpage+1}">下一页</a>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; <a href="dispEmp.do?cp=${pg.pagemax}">尾页</a></p><br/>
     <a href="addemp.jsp">继续添加</a>
  </body>
</html:html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值