struts 2.1.6 001 domo

本文介绍了一个简单的Struts2应用示例,包括所需的6个jar包、web.xml配置、struts.xml配置文件放置位置及内容、HelloWorldAction实现类等关键信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

6个jar 包

 

web.xml的配置

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4"
 xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

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

</web-app>

 

struts.xml 放到类路径下,即src目录下

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

<struts>

    <constant name="struts.devMode" value="true" />
    <constant name="struts.i18n.reload" value="true" />
    <constant name="struts.serve.static.browerCache" value="true" />
   
    <!-- http://localhost:8080/struts_2.1.6_001/test/helloword.action  -->
    <!-- hello.jsp放到WEB-INF路径下是因为直接访问是没有意义的 -->
    <package name="demo" namespace="/test" extends="struts-default">
     <action name="helloword" class="com.scottwong.HelloWorldAction">
      <result name="success">/WEB-INF/page/hello.jsp</result>
     </action>
    </package>
   


</struts>

 

Action

package com.scottwong;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorldAction extends ActionSupport {
 
 private String message;
 
 
 public String getMessage() {
  return message;
 }


 @Override
 public String execute() throws Exception {
  this.message="我的第一个struts2应用...";
  return this.SUCCESS;
 }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值