ssm 프레임 워 크 학습 의 (1) -- struts 2 주해
                                            
 5039 단어  struts2
                    
제1 부분 struts 2 주해
1. 인터넷 에서 많은 자 료 를 검색 하고 사용 하 는 가방 이 다 르 기 때문에 각종 NoClassDef Foundation Error 를 자주 만 날 수 있 습 니 다.
그래서 직접 홈 페이지 에 가서 최신 struts 가방 을 다운로드 합 니 다. 2.3.4. 1
http://struts.apache.org/download.cgi#struts2341
2. 웹 프로젝트 를 새로 만 들 었 습 니 다. 방금 다운로드 한 가방 의 모든 jar 를 lib 에 추가 합 니 다.
3. 웹. xml 설정
    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">
	<display-name>struts2</display-name>
	<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>*.action</url-pattern>
	</filter-mapping>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
</web-app>
    4 새 action: LoginAction. java
     package com.rabbit.demo.action;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import com.opensymphony.xwork2.ActionSupport;
/**
 * 
 * @author hackpro
 * @date   2012-11-15   11:27:11
 */
/*
 *    Demo           Struts2 Action   
 *                  struts.xml  Action        ,             Action 
 */
// /////////       Action///////////////////////////
@ParentPackage("struts-default")
//   
@Namespace("")
@Results({
		@Result(name = com.opensymphony.xwork2.Action.SUCCESS, location = "/msg.jsp"),
		@Result(name = com.opensymphony.xwork2.Action.ERROR, location = "/erlogin.jsp") })
// @ExceptionMappings          
// @ExceptionMapping         
@ExceptionMappings({ @ExceptionMapping(exception = "java.lange.RuntimeException", result = "error") })
public class LoginAction extends ActionSupport {
	private static final long serialVersionUID = -2554018432709689579L;
	private String loginName;
	private String pwd;
	// @Action(value="login")              URL。  ,      Action  ,       。
	@Action(value = "loginName")
	public String login() throws Exception {
		if ("ztt".equalsIgnoreCase(loginName.trim())
				&& "lve".equalsIgnoreCase(pwd.trim())) {
			return SUCCESS;
		} else {
			System.out.println("===========");
			return ERROR;
		}
	}
	@Action(value = "add", results = { @Result(name = "success", location = "/index.jsp") })
	public String add() throws Exception {
		return SUCCESS;
	}
	public String getLoginName() {
		return loginName;
	}
	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
}
     4. 위의 action 을 보 았 기 때문에 다 jsp 를 만들어 야 한 다 는 것 을 알 고 있 습 니 다.
5. 프로젝트 를 시작 하면 spring 의 관련 가방 이상 을 보고 하고 jar 를 점차적으로 삭제 할 수 있 습 니 다.
asm-3.3.jar
asm-commons-3.3.jar
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
ognl-3.0.5.jar
struts2-convention-plugin-2.3.4.1.jar
struts2-core-2.3.4.1.jar
xwork-core-2.3.4.1.jar
물론 이 방법 은 매우 멍청 하지만, 풋내기 급 의 나 는 늘 실용적이다.
6. 로그 인 테스트
7. 완벽 한 배치 가 필요 한 곳 이 많 습 니 다. 길이 멀 어 요.
8. 소스 코드
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
apache struts2 취약점 검증이번에는 보안 캠프의 과제였던 apache struts2의 취약성에 대해 실제로 손을 움직여 실행해 보고 싶습니다. 환경 VirtualBox에서 브리지 어댑터 사용 호스트:macOS 10.12 게스트:ubuntu 1...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.