配置struts-config.xml文件内容下面具体讲解
开发第一个Struts程序
web.xml如上
struts-config.xml
? ? ? ?
? ? ? ?
? ? ? ?
? ? ? ?
? ? ? ?
? ? ? ?
? ? ? ?
? ? ? ?
? ? ? ? ? ? /success.jsp
? ? ? ?
? ? ? ?
LoginAction.java
package com.linuxidc.action;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
/**
?*
?* @author 偶my耶
?*? ? action
?*/
public class LoginAction extends ActionSupport {
? ? /**
? ? *
? ? */
? ? HttpServletRequest request = ServletActionContext.getRequest();
? ? private static final long serialVersionUID = 1L;
? ? @Override
? ? public String execute() throws Exception {
? ?
? ? ? ? String? name=request.getParameter("user_name");//获得user_name
? ? ? ? request.setAttribute("name",name);//设值
? ? ? ? return SUCCESS;
? ? }
}
jsp界面
index.jsp?
?
?
? ?
?
success.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 'index.jsp' starting page
?
? <%? ? String name=(String)request.getAttribute("name");
? %>
?
? 欢迎<%=name %>
? ? 跳转成功!!
?
?
Struts工作原理
?
Struts是MVC设计模式的一种具体的实现;
Struts中的核心类就是ActionForm、Action,都需要在struts-config.xml文件中进行配置。