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

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

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


    今天我用myeclipse做了一個(gè)關(guān)于struts2的小例子,和大家分享當(dāng)然工程新建和服務(wù)器配置就不多說(shuō)了!導(dǎo)入stuts2 的 jar包也不多說(shuō)了!
    首先配置web-inf下的web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4"
        xmlns
    ="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi
    ="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation
    ="http://java.sun.com/xml/ns/j2ee
        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    >
     
    <filter>
     
    <filter-name>struts2</filter-name>
     
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    </web-app>




    右擊src建立并配置struts.xml  

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd"
    >
       
    <struts>
       
    <package name="struts2"  extends="struts-default">
       
    <action name="login" class="com.test.action.LoginAction">
       
    <result name="input">login2.jsp</result>
       
    <result>/result.jsp</result>
       
    <result name="failer">/login2.jsp</result>
       
    </action>
       
    </package>

    </struts>



    并在src目錄下建立包c(diǎn)om.test.action,里面新建一個(gè)java類(lèi)LoginAction.java
    /*
     *Coryright(c)2008 yxc & njust
     *All rights reserved.
    */
    package com.test.action;

    import com.opensymphony.xwork2.ActionSupport;

    public class LoginAction extends ActionSupport{  //此處繼承的父類(lèi)ActionSupport就是struts2的一個(gè)典型應(yīng)用
        private String username;
        
    private String password;
        
    public String getUsername()
        {
            
    return username;
        }
        
    public void setUsername(String username)
        {
            
    this.username = username;
        }
        
    public String getPassword()
        {
            
    return password;
        }
        
    public void setPassword(String password)
        {
            
    this.password = password;
        }
        
    public String execute() throws Exception
        {
            
    if("hello".equals(this.getUsername().trim())&&"word".equals(this.getPassword().trim()))
            {
                
    return "success";
            }
            
    else
            {
                
    this.addFieldError("username""username or password error!!!!");
                
    return "failer";
            }
        }
        @Override
        
    public void validate() {    //驗(yàn)證
           
            
    if(null==this.getUsername()|| "".equals(this.getUsername().trim()))
            {
                
    this.addFieldError("username""username request");
            }
            
    if(null==this.getPassword()||"".equals(this.getPassword().trim()))
            {
                
    this.addFieldError("password""password request");
            }
        }
       

    }

    在webroot下建立如下jsp文件,login2.jsp,result.jsp


    login2.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding
    ="ISO-8859-1"%>
    <%@ taglib prefix="s"  uri="/struts-tags" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <s:form  action="login">
    <s:textfield name="username" label="username"></s:textfield>
    <s:password name="password" label="password"></s:password>
    <s:submit name="submit"></s:submit>
    </s:form>
    </body>
    </html>



    result.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
        
    <head>
        
    <base href="<%=basePath%>">
        
    <title>My JSP 'result.jsp' starting page</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>
        username:${requestScope.username}
    <br>
        password:${requestScope.password}
    </body>
     
    </html>


    這樣就實(shí)現(xiàn)了簡(jiǎn)單的固定用戶登陸,username:hello   password:word  

    實(shí)現(xiàn)界面







    Feedback

    # re: 實(shí)現(xiàn)一個(gè)簡(jiǎn)單的struts2應(yīng)用(實(shí)現(xiàn)登陸)[未登錄](méi)  回復(fù)  更多評(píng)論   

    2014-11-13 14:30 by 1

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     

    posts - 5, comments - 10, trackbacks - 0, articles - 0

    Copyright © yxc

    主站蜘蛛池模板: 亚洲视频在线播放| 三年片在线观看免费观看大全一| 亚洲最大的成网4438| 亚洲女同成人AⅤ人片在线观看 | 国产免费131美女视频| 中文字幕在线免费| 最近免费字幕中文大全| 亚洲高清毛片一区二区| 亚洲18在线天美| 亚洲视频一区调教| 国产亚洲成av片在线观看| 免费在线一级毛片| 精品熟女少妇AV免费观看| 最近中文字幕2019高清免费| 久久国产精品免费一区二区三区 | 老司机在线免费视频| 毛片在线全部免费观看| 2022免费国产精品福利在线 | 午夜精品在线免费观看| 中文字幕无码播放免费| 日韩在线不卡免费视频一区| 91精品成人免费国产| 成年免费a级毛片| 国产天堂亚洲国产碰碰| 国产精品亚洲一区二区在线观看 | 成人免费视频观看无遮挡| 91大神免费观看| 无码精品国产一区二区三区免费| 成人妇女免费播放久久久| 9久热精品免费观看视频| av成人免费电影| 人成午夜免费大片在线观看| 一道本不卡免费视频| CAOPORN国产精品免费视频| 国产精品1024在线永久免费| 国产国产人免费人成成免视频| 一道本在线免费视频| 国产在线观看xxxx免费| a级毛片无码免费真人久久| 日韩免费高清播放器| 久久永久免费人妻精品下载 |