Struts2配置

上传jar包,复制jar包到WebRoot/WEB-INF/lib下

jar包 作用
commons-fileupload-1.2.2.jar 文件上传
commons-io-2.0.1.jar fileupload依赖于io
commons-logging-1.1.1.jar 关于日志处理的
ognl-3.0.5.jar ognl表达式
struts2-core-2.3.4.jar struts2框架核心库包
xwork-core-2.3.4.jar Xwork的核心类库
freemarker-2.3.19.jar 模板引擎
javassist-3.11.0.GA.jar 编辑Java字节码的类库
commons-lang3-3.1.jar 用来处理Java基本对象方法的工具类包

web.xml配置



  
    index.jsp
  
    
  
    struts2
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  
  
    struts2
    /*
  
  

在src下新建一个xml文件struts.xml



    

    
         
            /result.jsp
        
    

src下新建一个package com.sshlearn.action,并新建class loginAction

package com.sshlearn.action;

public class LoginAction {
    private String username;
    private String password;
    
    public String execute() {
        System.out.println(username+"==="+password);
        return "success";
    }
    
    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;
    }
}

新建login.jsp文件

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



  
    
    
    My JSP 'login.jsp' starting page
    
    
    
        
    
    
    

  
  
  
      


新建result.jsp

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



  
    
    
    My JSP 'result.jsp' starting page
    
    
    
        
    
    
    

  
  
  
     username:${requestScope.username} 
password:${requestScope.password}

项目目录结构如图

项目目录结构.jpg

访问地址localhost:8080/sshlearn/login.jsp,页面如下

login.jpg

跳转到result.jsp页面,结果如下

result.jpg

你可能感兴趣的:(Struts2配置)