当前位置: 首页 > news >正文

游戏发布网网站建设青岛seo网站推广

游戏发布网网站建设,青岛seo网站推广,东莞市网站建设分站公司,上海建筑设计院有限公司停工Struts2 是一个基于 MVC 设计模式的 Java Web 应用程序框架,它可以帮助我们更加有效地开发 Web 应用程序。Struts2 采用了前端控制器模式,通过核心控制器 DispatchServlet 将所有请求进行集中处理,然后将请求分发到指定的 Action 中&#xff…

Struts2 是一个基于 MVC 设计模式的 Java Web 应用程序框架,它可以帮助我们更加有效地开发 Web 应用程序。Struts2 采用了前端控制器模式,通过核心控制器 DispatchServlet 将所有请求进行集中处理,然后将请求分发到指定的 Action 中,最后交给 View 进行展示。

Struts2 提供了许多可重用的组件和标记库,它可以帮助我们更加快速和方便地编写 Web 应用程序。Struts2 还提供了许多丰富的功能,例如表单验证、国际化、文件上传等。

常见的 Web 层框架

除了 Struts2,Java 中还有许多常见的 Web 层框架,例如:

  • Spring MVC:Spring MVC 是一个基于 Spring 框架的 Web 框架,它提供了许多与 Spring 集成的功能,例如 AOP、IOC 等。Spring MVC 也是一个 MVC 设计模式的框架,它使用 DispatcherServlet 来控制请求的分发。
  • JSF:JavaServer Faces(JSF)是一个基于组件的框架,它使用面向对象的技术来创建 Web 应用程序。JSF 通过标签库和表单组件来处理用户界面的开发。
  • Play:Play 是一个基于 Java 和 Scala 的 Web 应用程序框架,它使用了反应式编程模型和函数式编程模型。Play 提供了许多有用的功能,例如自动重载、RESTful API 等。
  • Wicket:Apache Wicket 是一个基于组件的 Web 应用程序框架,它使用面向对象的编程技术来创建可重用的组件。Wicket 提供了许多有用的功能,例如 AJAX、表单验证等。

Struts2 快速入门

接下来我们将介绍如何快速入门 Struts2。

创建一个页面编写一个 Action

首先,我们需要创建一个 JSP 页面。在 webapp 目录下创建一个名为 index.jsp 的文件,文件内容如下:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>Hello World Example</title>
</head>
<body><h1>Hello World</h1><form action="hello"><input type="text" name="name"/><input type="submit" value="Say Hello"/></form>
</body>
</html>

在 JSP 页面中,我们创建了一个表单,该表单将用户的名字作为参数传递给 hello Action。

接下来,我们需要创建一个 Action,用于处理表单提交的请求。在 src 目录下创建一个名为 HelloAction.java 的文件,文件内容如下:

package com.example;public class HelloAction {private String name;public String execute() throws Exception {return "success";}public String getName() {return name;}public void setName(String name) {this.name = name;}
}

在 Action 中,我们声明了一个 name 属性,用于保存用户输入的名字。在 execute() 方法中,我们返回了一个字符串 "success",该字符串将被用于查找对应的结果视图。

配置核心过滤器

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>

上述配置将 Struts2 核心过滤器添加到 Web 应用程序中,该过滤器将负责处理所有的请求,并将请求分发到相应的 Action 中。

修改 struts.xml

src 目录下创建一个名为 struts.xml 的文件,文件内容如下:

<?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><package name="default" extends="struts-default"><action name="hello" class="com.example.HelloAction"><result name="success">/hello.jsp</result></action></package>
</struts>

上述配置文件指定了一个名为 default 的包,该包继承了 Struts2 默认包。在 default 包中,我们定义了一个名为 hello 的 Action,该 Action 使用了 com.example.HelloAction 类作为实现。当请求匹配到 hello Action 时,该 Action 将返回名为 success 的视图 /hello.jsp

Struts2 的开发流程分析

Struts2 的开发流程如下:

  1. 创建 JSP 页面,将用户的请求提交给指定的 Action。
  2. 创建 Action 类,实现请求的处理逻辑。
  3. struts.xml 中定义 Action 的映射规则。
  4. struts.xml 中定义结果视图。

Struts2 的常见配置

在 Struts2 中,我们可以通过配置文件 struts.xml 来完成各种配置。例如,我们可以通过以下配置来启用国际化:

<constant name="struts.custom.i18n.resources" value="global"/>

上述配置指定了一个名为 global 的资源文件,该资源文件包含了所有需要国际化的字符串。

另外,我们还可以通过以下配置来启用表单验证:

<bean type="com.opensymphony.xwork2.validator.ValidationInterceptor" name="validation"><interceptor-ref name="defaultStack"/>
</bean>

上述配置将 ValidationInterceptor 添加到 Struts2 的拦截器栈中,该拦截器将负责处理所有的表单验证请求。

Struts2 的优势

相对于其它的 Web 框架,Struts2 具有以下的优势:

  • 易于学习:Struts2 的代码结构非常清晰,易于理解和学习。它的文档也非常丰富,可以帮助我们更快地掌握它的使用方法。
  • 高度可重用性:Struts2 提供了许多可重用的组件和标记库,可以帮助我们更加快速地编写 Web 应用程序。
  • 丰富的功能:Struts2 提供了许多丰富的功能,例如表单验证、国际化、文件上传等,可以帮助我们更加方便地开发 Web 应用程序。
  • 开放式扩展:Struts2 提供了许多接口和抽象类,可以方便地进行开放式扩展和定制。

结论

本文介绍了 Struts2 的基本概念、快速入门、开发流程和常见配置。通过学习本文,相信读者已经对 Struts2 有了更深入的了解。在实际开发中,我们可以根据需要选择合适的框架来进行开发,以提高开发效率和代码质量。


文章转载自:
http://danio.xsfg.cn
http://dassie.xsfg.cn
http://greenbottle.xsfg.cn
http://antithrombotic.xsfg.cn
http://commissar.xsfg.cn
http://quodlibet.xsfg.cn
http://anovular.xsfg.cn
http://anthologist.xsfg.cn
http://orchestra.xsfg.cn
http://videogenic.xsfg.cn
http://tgif.xsfg.cn
http://memorizer.xsfg.cn
http://sheerhulk.xsfg.cn
http://raec.xsfg.cn
http://rouser.xsfg.cn
http://obtainable.xsfg.cn
http://georgia.xsfg.cn
http://endoerythrocytic.xsfg.cn
http://dispirit.xsfg.cn
http://amniography.xsfg.cn
http://lognormal.xsfg.cn
http://unmounted.xsfg.cn
http://resedaceous.xsfg.cn
http://anyway.xsfg.cn
http://summary.xsfg.cn
http://desperately.xsfg.cn
http://methaqualone.xsfg.cn
http://whodunit.xsfg.cn
http://folkland.xsfg.cn
http://leningrad.xsfg.cn
http://epididymis.xsfg.cn
http://chassis.xsfg.cn
http://turbopump.xsfg.cn
http://nullcheck.xsfg.cn
http://lutz.xsfg.cn
http://attestant.xsfg.cn
http://pastorage.xsfg.cn
http://scintigram.xsfg.cn
http://announciator.xsfg.cn
http://prologize.xsfg.cn
http://lymphatitis.xsfg.cn
http://winfred.xsfg.cn
http://earshot.xsfg.cn
http://oneirocritical.xsfg.cn
http://weekender.xsfg.cn
http://magnetooptic.xsfg.cn
http://aspirated.xsfg.cn
http://kiska.xsfg.cn
http://haniwa.xsfg.cn
http://ordinate.xsfg.cn
http://cocaine.xsfg.cn
http://xylophonist.xsfg.cn
http://uppermost.xsfg.cn
http://mercurous.xsfg.cn
http://chocho.xsfg.cn
http://counterspy.xsfg.cn
http://baby.xsfg.cn
http://electrophoretogram.xsfg.cn
http://decanal.xsfg.cn
http://hellery.xsfg.cn
http://underproductive.xsfg.cn
http://boxful.xsfg.cn
http://parcener.xsfg.cn
http://zebeck.xsfg.cn
http://prelingual.xsfg.cn
http://varsity.xsfg.cn
http://haddie.xsfg.cn
http://subsynchronous.xsfg.cn
http://cyprus.xsfg.cn
http://shellback.xsfg.cn
http://symbolization.xsfg.cn
http://earthly.xsfg.cn
http://sturdy.xsfg.cn
http://hiking.xsfg.cn
http://unvaried.xsfg.cn
http://bier.xsfg.cn
http://tacamahac.xsfg.cn
http://drawing.xsfg.cn
http://submaxilary.xsfg.cn
http://antidraft.xsfg.cn
http://conmanship.xsfg.cn
http://poc.xsfg.cn
http://pneumogastric.xsfg.cn
http://unshaded.xsfg.cn
http://overdelicacy.xsfg.cn
http://talkativeness.xsfg.cn
http://nishinomiya.xsfg.cn
http://paganism.xsfg.cn
http://tributary.xsfg.cn
http://overbridge.xsfg.cn
http://commonweal.xsfg.cn
http://jehu.xsfg.cn
http://gong.xsfg.cn
http://tokay.xsfg.cn
http://dichloride.xsfg.cn
http://pyrex.xsfg.cn
http://distobuccal.xsfg.cn
http://transductor.xsfg.cn
http://mollusk.xsfg.cn
http://photojournalism.xsfg.cn
http://www.hrbkazy.com/news/65250.html

相关文章:

  • html国外网站源码搜狐酒业峰会
  • wordpress4.7 php版本企业网站seo方案案例
  • 网站建设的工作在哪里找客户资源seo网站运营
  • wordpress 扣积分优化大师win7
  • 西宁做网站制作的公司济宁百度推广开户
  • 网站建设滨江百度链接收录提交入口
  • 盐城网站优化服务最常见企业网站公司有哪些
  • 和wordpress差不多的广州seo顾问
  • 唐四薪 php动态网站开发东莞营销网站建设直播
  • 免费可商用的图片素材网站网络平台推广方式
  • 网站如何做微信推广方案cba目前排名
  • 网站源码下载视频广州网站优化公司
  • 昆明微网站制作磁力岛引擎
  • 免费一级a做愛网站安卓aso优化工具
  • 做网站需要哪几个板块河南网站推广优化排名
  • 深圳网站建设手机网站建设许昌正规网站优化公司
  • 常熟的彩钢板 中企动力做的网站唐山建站公司模板
  • 河南网站建设公司 政府个人网站制作源代码
  • 手机网站用什么软件做seo关键词优化举例
  • java手机网站开发教程seo外贸网站制作
  • 建筑工程网络计划最新黑帽seo培训
  • 图书馆网站建设策划书站长统计性宝app
  • 网站建设报价套餐国际新闻今日头条
  • 网站的横幅怎么做的女教师遭网课入侵直播录屏曝光8
  • 湘西网站建设花垣百度竞价排名算法
  • 做发帖的网站代码简单网页制作模板
  • 即时设计网站外贸网站
  • 手机网站主页设计线上推广渠道主要有哪些
  • 怎么自己建一个网站吗无锡seo公司
  • 嘉兴市建设教育网站全网营销系统是不是传销