首页 技术 正文
技术 2022年11月11日
0 收藏 549 点赞 2,618 浏览 2306 个字

一、Struts下载地址

http://struts.apache.org/download.cgi

二、导入包、配置Web.xml和struts.xml

在下载的包中从示例中找到一些包就可以

struts2-2.3.4.1-all\struts-2.3.4.1\apps\struts2-blank\WEB-INF\lib

在Web.xml在加入

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

struts.xml可以在struts2-2.3.4.1-all\struts-2.3.4.1\apps\struts2-blank\WEB-INF\classes下找到示例更改即可

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"><struts>
<!--
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" /> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index" /> <global-results>
<result name="error">/error.jsp</result>
</global-results> <global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings> <action name="index">
<result type="redirectAction">
<param name="actionName">HelloWorld</param>
<param name="namespace">/example</param>
</result>
</action>
</package> <include file="example.xml"/>
class="com.opensymphony.xwork2.ActionSupport"
-->
<!-- Add packages here -->
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default"> <action name="hello" class="com.pb.web.action.HelloAction3">
<result>
/helloStruts.jsp
</result>
</action>
</package>
</struts>

三、实现

action

package com.pb.web.action;import com.opensymphony.xwork2.ActionSupport;
/*
* 第三种 继承 ActionSupport类它是Action的实现类
*/
public class HelloAction3 extends ActionSupport { /**
*
*/
private static final long serialVersionUID = 1L; @Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return "success";
}}

页面

helloStruts.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>HelloStruts</title>
</head>
<body>
<h1 align="center">Hello Struts!</h1>
</body>
</html>

在地址栏中输入http://localhost:8080/StrutsDemo1/hello.action

以hello.action访问就可以跳到helloStruts.jsp页面

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,028
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,518
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,367
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,858