struts 2 패키지 및 설정

5184 단어 struts2
struts 2 의 핵심 사상
MVC 디자인 모델 의 실현
컨트롤 러 입 니 다.
FilterDispatcher 와 Action
풍부 한 보 기 를 제공 하 였 다.
JSP
FreeMarker/Velocity
보고서 지원
AOP 방면 프로 그래 밍
대량의 Interceptor 제공
사용자 정의 interceptor 지원
 
 
1. 웹. xml 의 설정 은 다음 과 같 습 니 다.
<filter> 
	<filter-name>struts2</filter-name> 
	<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> 
<filter-mapping> 
	<filter-name>struts2</filter-name> 
	<url-pattern>/*</url-pattern> 
</filter-mapping> 

 
2.struts2.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="default" namespace="/" extends="struts-default">
        <action name="login" class="com.gsww.kingreturns.struts2.excise.LoginAction" method="execute">
            <result name="success">/welcome.jsp</result>
            <result name="login">/login.jsp</result>
        </action>
    </package>

</struts>

      :package-name:       package;      、      ;    package   ;

              package--namespace:        ( struts1  );   action          ;

              package--extends:      package            ;
             action--name:     package      action;      、      ;   action          ;

              action--class:action     (  +  );

       action--method:action       ;

 
3. LoginAction. class 작성
package com.gsww.kingreturns.struts2.excise;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {//     ActionSupport 。         SUCCESS, LOGIN      execute   


 private static final long serialVersionUID = 1L;
 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;
 }

 @Override
 public String execute() throws Exception {
  if("haha".equals(username) && "hehe".equals(password))//        =haha    =hehe,   SUCCESS;  ,  LOGIN
   return SUCCESS;
  return LOGIN;
 }
}

 
login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>Login</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">

  </head>
  
  <body>
   
   <s:form action="/login" method="post">
    <s:label value="    "></s:label>
    <s:textfield name="username" label="  " />
    <s:password name="password" label="  " />
    <s:submit value="  " />
   </s:form>
  
  </body>
</html>

 welcome.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'welcome.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">
 

  </head>
  
  <body>
     ${username }!
  </body>
</html>


 
 

좋은 웹페이지 즐겨찾기