Struts2 入门

以最新的sturts2.1.8为例:

下载资源struts-2.1.8.1-all.zip http://struts.apache.org/download.cgi#struts2181f

 

 

1.解压struts-2.1.8.1-all.zip 加载lib中的Jar包

 

2.apps下解压空war包拷贝web.xml 配置filter拦截器

 

     <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>

 

3.配置struts.xml

<constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true" />

       <package name="default" namespace="/" extends="struts-default">
        <default-action-ref name="index" />
        <action name="myfirst">
            <result >
                /myfirst.jsp
            </result>
        </action>
    </package>

 <constant name="struts.devMode" value="true" />指明开发模式设为true,在改变配置文件时动态加载不需重新启动服务器

 

4.根目录下添加myfirst.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
Hello,This is my first example!
</body>
</html>

 

5.访问:http://localhost:8080/context-root_name/myfirst  第一个例子就跑起来了。

 

你可能感兴趣的:(apache,html,xml,jsp,struts)