<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 33,  comments - 11,  trackbacks - 0

    1.index.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"%>

    <html>
     <head>
      <title>紹興縣政民互動系統后臺</title>
      <link href="css/module.css" rel="stylesheet" type="text/css">
      <link href="css/base.css" rel="stylesheet" type="text/css">
    <script type="text/javascript">
    function beforeSubmit(loginForm){
    if(loginForm.username.value==''){
    alert('用戶名不能為空!');
    loginForm.username.focus();
    return false;
    }
    if(loginForm.password.value==''){
    alert('密碼不能為空!');
    loginForm.password.focus();
    return false;
    }
    if(loginForm.textcode.value==''){
    alert('驗證碼不能為空!');
    loginForm.textcode.focus();
    return false;
    }
    return true;
    }
    </script>
     </head>
     <body id="mybody" class="loginbody"
      onKeyDown="if(event.keyCode==13)loginFunc();">

      <div class="logintitle">
       <img src="images/login_06.gif">
      </div>
      <div class="rjlogo">
       <table border="0" cellspacing="0" cellpadding="0">
        <tr>
         <td valign="bottom">
          建議使用Internet Explorer 6.0版本瀏覽器、1024*768分辨率以上瀏覽本系統
          <br>
          Copyright © 2006-2008 浙江榕基信息技術有限公司
         </td>
         <td>
          <img src="images/login_10.gif">
         </td>
        </tr>
       </table>
      </div>
      <div class="loginbg">
       <div class="loginform">
        <html:form action="/login?method=login"
         onsubmit="return beforeSubmit(this);" method="post" enctype="multipart/form-data">
         <table width="200" border="0" cellpadding="1" cellspacing="0"
          id="ta1">
          <tr>
           <td align="right">
            英文名稱:
           </td>
           <td>
            <html:text property="username"
             style=" width:120px; height:18px; border:#FFFFFF solid 1px;" />
           </td>
          </tr>
          <tr>
           <td align="right">
            用戶密碼:
           </td>
           <td>
            <html:password property="password"
             style=" width:120px; height:18px; border:#FFFFFF solid 1px;" />
           </td>
          </tr>
          <tr>
           <td align="right">
            驗證碼:
           </td>
           <td>
            <html:text property="textcode"
             style="width:60px;height:18px; border:#FFFFFF solid 1px;"
             maxlength="4" /><html:image src="image.jsp" border="0" align="absmiddle"></html:image>
           </td>
          </tr>
          <tr>
           <td align="right">
            上傳圖片:
           </td>
           <td>
            <html:file property="file" value="瀏覽"
             style="width:30px;height:18px; border:#FFFFFF solid 1px;"
             maxlength="4" />
           </td>
          </tr>
          <tr>
          <td>&nbsp;</td>
           <td align="left">
            <html:submit
             style="background:url(images/login_05.gif); width:76px; height:26px; border:0;"
             value="登陸"></html:submit>
           </td>
          </tr>
         </table>
        </html:form>
       </div>
      </div>
     </body>
    </html>

    2.LoginForm.java

    /*
     * Generated by MyEclipse Struts
     * Template path: templates/java/JavaClass.vtl
     */
    package web.form;

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

    /**
     * MyEclipse Struts Creation date: 05-19-2009
     *
     * XDoclet definition:
     *
     * @struts.form name="loginForm"
     */
    @SuppressWarnings("serial")
    public class LoginForm extends ActionForm {
     /*
      * Generated fields
      */

     /** username property */
     private String username;

     /** password property */
     private String password;

     /** textcode property */
     private String textcode;

     /** FormFile property */
     private FormFile file;

     /*
      * 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
     }

     public String getPassword() {
      return password;
     }

     public void setPassword(String password) {
      this.password = password;
     }

     public String getUsername() {
      return username;
     }

     public void setUsername(String username) {
      this.username = username;
     }

     public String getTextcode() {
      return textcode;
     }

     public void setTextcode(String textcode) {
      this.textcode = textcode;
     }

     public FormFile getFile() {
      return file;
     }

     public void setFile(FormFile file) {
      this.file = file;
     }

     /**
      * Returns the username.
      *
      * @return String
      */

    }

    3.loginAction

    /*
     * Generated by MyEclipse Struts
     * Template path: templates/java/JavaClass.vtl
     */
    package web.action;

    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.actions.DispatchAction;
    import web.form.LoginForm;
    import service.Service;
    import vo.User;

    /**
     * MyEclipse Struts Creation date: 09-27-2006
     *
     * XDoclet definition:
     *
     * @struts.action path="/login" name="loginForm" input="/login.jsp"
     *                scope="request" validate="true"
     * @struts.action-forward name="fail" path="/login.jsp"
     * @struts.action-forward name="succeed" path="/welcome.jsp"
     */
    public class LoginAction extends DispatchAction {
     /*
      * Generated Methods
      */
     /**
      * Method execute
      *
      * @param mapping
      * @param form
      * @param request
      * @param response
      * @return ActionForward
      */
     private Service service;

     public void setService(Service service) {
      this.service = service;
     }

     public Service getService() {
      return service;
     }


     public ActionForward login(ActionMapping mapping, ActionForm form,
       HttpServletRequest request, HttpServletResponse response) {
      LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method
      // stub
      
      
      
      User user = new User();
      user.setPassword(loginForm.getPassword());
      user.setUsername(loginForm.getUsername());

      String filepath = "D:/Upload\\";

      if (!new File(filepath).isDirectory()) {
       new File(filepath).mkdir();
      }

      String file_hz=loginForm.getFile().getFileName();

      String file_name = filepath +file_hz;
      System.out.println(file_name);

      FileOutputStream out;
      try {
       out = new FileOutputStream(new File(file_name));
       out.write(loginForm.getFile().getFileData());
       out.close();
      } catch (FileNotFoundException e) {
       e.printStackTrace();
      } catch (IOException e) {
       e.printStackTrace();
      }

      String code = "";
      code = (String) request.getSession().getAttribute("rand");
      if (code.trim().equals(loginForm.getTextcode())) {
       System.out.print("ok1");
       if (service.isValid(user)) {
        System.out.print("ok");
        return mapping.findForward("succeed");
       } else {
        System.out.print("no");
        return mapping.findForward("fail");
       }
      } else {
       return mapping.findForward("fail");
      }
     }
    }


    4.取得文件名亂碼解決
    重寫org.apache.struts.upload.CommonsMultipartRequestHandler這個類
    找到public void handleRequest(HttpServletRequest request)
    throws ServletException方法

    DiskFileUpload upload = new DiskFileUpload();

    后邊加上
    upload.setHeaderEncoding(request.getCharacterEncoding());
    編譯后放到struts.jar包里覆蓋原來的
    posted on 2009-06-02 10:26 方濤升 閱讀(283) 評論(0)  編輯  收藏 所屬分類: struts

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    <2009年6月>
    31123456
    78910111213
    14151617181920
    21222324252627
    2829301234
    567891011

    常用鏈接

    留言簿(2)

    隨筆分類

    隨筆檔案

    文章分類

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲国产精品无码久久久秋霞1 | 亚洲人成网站在线播放vr| 亚洲人成色777777精品| 青青久在线视频免费观看| 亚洲性猛交xx乱| 在线观看免费视频资源| 色婷婷亚洲十月十月色天| 免费精品无码AV片在线观看| 亚洲成人免费在线| 99视频在线免费| 亚洲精品永久www忘忧草| 最近免费中文字幕大全高清大全1 最近免费中文字幕mv在线电影 | 免费h成人黄漫画嘿咻破解版| 韩国亚洲伊人久久综合影院| 国产美女精品久久久久久久免费| 亚洲av日韩综合一区久热| 国产在线观看免费不卡| 污视频网站免费观看| 亚洲中文字幕伊人久久无码| 亚洲黄片手机免费观看| 亚洲中文久久精品无码ww16| 国产日韩AV免费无码一区二区| 久热综合在线亚洲精品| 久久ww精品w免费人成| 亚洲另类精品xxxx人妖| 成年女人免费碰碰视频| 色五月五月丁香亚洲综合网| 亚洲A∨午夜成人片精品网站| 国产福利在线观看永久免费| 国产亚洲婷婷香蕉久久精品 | 野花高清在线电影观看免费视频| 国产午夜亚洲精品| 国产一区二区三区免费视频| 一区二区视频免费观看| 国产亚洲综合网曝门系列| 99久在线国内在线播放免费观看| 亚洲国产一区在线观看| 国产精品成人免费综合| fc2免费人成为视频| 亚洲成A∨人片在线观看不卡| 222www在线观看免费|