Chinaunix首页 | 论坛 | 博客
  • 博客访问: 327394
  • 博文数量: 96
  • 博客积分: 2041
  • 博客等级: 大尉
  • 技术积分: 1080
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-20 14:08
文章分类

全部博文(96)

文章存档

2015年(2)

2013年(1)

2012年(93)

分类: 系统运维

2012-01-20 14:15:19

环境:myeclipse7.5 + tomcat6.0

用到了9个jar包,如图。红色圈的为容易漏加的。

 
注意需在tomcat的server.xml中加
 
LoginAction.java

package com.shengsiyuan.struts2;

public class LoginAction
{
 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()
 {
   return "SUCCESS" ;
  
 }
 
 
}
struts.xml


    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "">

 
  
   result.jsp
  

  
  

struts.xml控制着总流程:(login.jsp中:

) 名为login的action文件映射到com.shengsiyuan.struts2.LoginAction(实例化生成一个对象,每一次请求都生成一个对象),并通过反射机制调用setter,getter方法设置username和password。最后执行后面的execute()方法,execute()返回SUCCESS,result.jsp ,即名返回值SUCCESS的文件跳转到result.jsp页面

web.xml


 xmlns=""
 xmlns:xsi=""
 xsi:schemaLocation="
 ">
 
 

 struts2
 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
 
 

 



 struts2
 /*


 

login.jsp

<%@ page language="java" pageEncoding="ISO-8859-1"%>


 
 username:

 password:

 
 
 



 

result.jsp

<%@ page language="java" pageEncoding="ISO-8859-1"%>



 username :${requestScope.username}

 password:${requestScope.password }


 

 

 

 

附1_头文件中引用的DTD部分内容:


    name CDATA #REQUIRED
    extends CDATA #IMPLIED
    namespace CDATA #IMPLIED
    abstract CDATA #IMPLIED
    externalReferenceResolver NMTOKEN #IMPLIED
>


    name CDATA #REQUIRED
    class CDATA #REQUIRED
    default (true|false) "false"
>


    name CDATA #REQUIRED
    class CDATA #REQUIRED
>


    name CDATA #REQUIRED
>


    name CDATA #REQUIRED
>


    name CDATA #REQUIRED
>


    name CDATA #REQUIRED
>


    class CDATA #REQUIRED
>


    name CDATA #REQUIRED
    class CDATA #IMPLIED
    method CDATA #IMPLIED
    converter CDATA #IMPLIED
>


    name CDATA #REQUIRED
>


    name CDATA #IMPLIED
    type CDATA #IMPLIED
>


    name CDATA #IMPLIED
    exception CDATA #REQUIRED
    result CDATA #REQUIRED
>


    file CDATA #REQUIRED
>


    type CDATA #IMPLIED
    name CDATA #IMPLIED
    class CDATA #REQUIRED
    scope CDATA #IMPLIED
    static CDATA #IMPLIED
    optional CDATA #IMPLIED
>


    name CDATA #REQUIRED
    value CDATA #REQUIRED   
>

 


 附2_struts-default.xml

    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "">


   
   

   
   

   
   
   

   
   
   

   
   
   
   

   
   
   

   

   
   

   
   
   
   

   
   
   

   
   

   

   
   
   

   
   

   
   

   
   

   

   
   
   
   
   
   
   
   
   

   
   

   

   
   

   
   
   
   

   
       
           
           
           
           
           
           
           
           
           
           
       

       
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           

           
           
               
               
               
               
               
               
               
                    dojo\..*,^struts\..*
               

               
           

           
           
               
               
               
           

           
           
               
               
           

           
           
               
               
           

           
           
               
               
           

           
           
               
               
           

           
           
               
               
               
               
               
               
                    dojo\..*,^struts\..*
               

               
               
               
               
               
               
               
               
                    dojo\..*,^struts\..*
               

               
               
                    input,back,cancel,browse
               

               
                    input,back,cancel,browse
               

           

           
           
               
               
               
               
               
               
               
               
               
               
               
               
               
               
                  dojo\..*,^struts\..*
               

               
               
                    input,back,cancel,browse
               

               
                    input,back,cancel,browse
               

               
           

           
           
               
           

           
           
               
                    input,back,cancel
               

               
               
                    input,back,cancel
               

           

      

       

       
   


 

 
 
阅读(1326) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:struts2输入校验

给主人留下些什么吧!~~