Struts2学习笔记(搭建struts框架)

1.添加jar包

所以需要的jar包:https://download.csdn.net/download/dazhi_boy/10745954

1.commons-fileupload    上传下载
2.commons-io            上传下载所需的io
3.commons-lang          优化了jdk的lang功能
4.freemarker            和标签有关??
5.javassist             不知是干什么的?字节码工具
6.ognl                  ognl表达式
7.struts2-core          struts核心
8.log4j-api             日志
9.log4j-core

2.web.xml添加过滤器

<filter>
	<filter-name>struts2</filter-name>
	<filter-class>
            org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
</filter>

<filter-mapping>
	<filter-name>struts2</filter-name>
	<url-pattern>/*</url-pattern>
</filter-mapping>

3.添加struts.xml文件到跟目录下(src下)内容如下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
    "http://struts.apache.org/dtds/struts-2.5.dtd">

<struts>

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

    <package name="basicstruts2" extends="struts-default">
        <action name="index" class="webTest.action.HelloAction" method="execute">
            <result name="success">/hello.jsp</result>
        </action>
    </package>

</struts>

4.添加action

package webTest.action;

import com.opensymphony.xwork2.ActionSupport;

public class HelloAction extends ActionSupport{

	private String name;

	   public String execute() throws Exception {
		   return "success";
	   }
	   
	   public String getName() {
	      return name;
	   }

	   public void setName(String name) {
	      this.name = name;
	   }

}

5.添加hello.jsp

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>
   Hello World, <s:property value="name"/>
</body>
</html>

6.注意

1> 过滤器中的struts入口函数

org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter 在struts-core中有

2>Struts.xml中的文件头

struts-2.5.18\src\apps\showcase\src\main\resources中有

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值