Struts的基本流程 [英] Basic flow of Struts

查看:97
本文介绍了Struts的基本流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习Struts,所以我将从Struts 1开始 我想知道一般流程.需要什么文件?

Well I want to study Struts so I am going to begin with Struts 1, I would like to know the general flow. What files are required?

struts-config.xml的功能是什么? validation.xml? validation-rules.xml 当您访问JSP页面并触发某个操作时,会发生什么? Action和Form类做什么?触发动作时首先调用哪个类.

Whats the function of struts-config.xml? validation.xml? validation-rules.xml When you visit your JSP page, and an action gets fired, what happens? What does the Action and Form class do? Which class is called first when an action gets fired.

我刚刚下载了示例表格,所有这些文件起初都很令人困惑.我想知道怎么做才能更好地了解Struts.

I just downloaded a sample form, and all these files are confusing at first. I would like to know whats going on to get a better idea of Struts.

推荐答案

您应该从关于Struts的教程开始,这将使它易于理解:D.您可以在网上找到很多东西,尤其是对于Struts1.此处是一个起点.

You should start with a tutorial on Struts, that will make it easy to understand :D. You can find plenty on the web, especially for Struts 1. Here is a starting point for example.

但仅出于此目的,这是一个高视角的演示文稿.

首先,将Struts ActionServlet 添加到您的web.xml文件,并将其配置为接受与特定映射匹配的请求.对于Struts,这是*.do(您可以为此拥有任何东西,*.do只是Struts社区中的一个约定).

First you add the Struts ActionServlet into your web.xml file and you configure it to accept requests that match a certain mapping. For Struts this is *.do (you can have whatever you want for this, *.do is just a convention in the Struts community).

现在,以这种*.do URL模式到达服务器的所有内容都将发送到ActionServlet.

Now, whatever arrives on the server with such a *.do URL pattern is sent to the ActionServlet.

现在,struts-config.xml文件的内容开始起作用. ActionServlet前端控制器,它仅分派给其他更合适的资源以进行特定处理.这些特定资源是 Action 类.

Now, the content of struts-config.xml file comes into play. The ActionServlet is a front controller which just dispatches to other more appropriate resources for specific processing. Those specific resources are the Action classes.

例如,您可以拥有一个LoginAction,它必须处理在login.do路径上到达的请求.在struts-config.xml中,您可以指定以下内容:login路径中的所有内容都必须发送到LoginAction类.

You can have for example a LoginAction that must process requests that arrive on the login.do path. In the struts-config.xml you specify this: everything that comes on the login path must be sent to LoginAction class.

您可以根据需要设置任意数量的声明,对于路径x调用XAction,对于y调用YAction等,等等.

And you can have as many declarations as you want, for path x call XAction, for y call YAction etc etc.

通常,您的客户端向服务器提交数据,这些数据是他输入到HTML表单中的数据.您需要在Action类中处理此数据.现在输入 ActionForm .

Normally your client submits data to the server, data that he inputs into a HTML form. This data you need to process in your Action class. Now enter ActionForm.

ActionForm是Struts框架用HTML表单中的数据填充的bean.代替执行request.getParameter("foo"),您可以使用例如formBean.getFoo()之类的对象.

The ActionForm is a bean that the Struts framework fills with the data from the HTML form. Instead of doing request.getParameter("foo") you can work with objects like formBean.getFoo() for example.

使用ActionFormAction类中进行处理后,您必须在某些视图中显示结果(顺便说一句,Struts是

Once you do your processing in the Action class using the ActionForm, you then must present the results in some view (by the way, Struts is a MVC framework so you must know a stuff or two about this also).

视图通常是JSP文件.从Action返回时,请按名称指定转发"位置(即转到哪个视图).现在,信息再次位于struts-config.xml文件中,在该文件中,视图名称已映射到JSP位置.

The views are normally JSP files. When you return from your Action, you specify a "forward" location by name (i.e. to what view to go). Now again the information is in the struts-config.xml file where the name of the view is mapped to a JSP location.

然后,框架将控制权转发给该JSP,JSP呈现数据,然后将其作为HTML发送给客户端(客户端将不再需要直接访问JSP,它们必须被Struts框架隐藏).

The framework will then forward control to that JSP, the JSP presents the data which is then sent to the client as HTML (the client will no longer need to access JSPs directly - they must be hidden by the Struts framework).

在新页面中,客户端再次执行一些请求,然后重复该过程.

In the new page the client again performs some requests and the process repeats.

好吧,这就是它所能获得的最高水平的展示.当然,还有很多,但是您在学习Struts时会发现它们.

Well, that's about as high presentation as it can get. Off course there is more than this, but you will discover them while learning about Struts.

对于validator-rules.xmlvalidation.xml,它们由与之集成通过使用插件来使用Struts (Struts的插件可以用来向其中添加新内容),还可以对用户输入内容进行验证.

As for the validator-rules.xml and validation.xml, those are used by the Validator framework which you can integrate with Struts by the use of a plugin (Struts has plugins you can use to add new stuff to it) to also add validation to the user's input.

好吧,就是这样.您可以在网络上找到很多教程,其中提供了更多详细信息,但希望能帮助您更好地开始学习.

Well, that is about it. You can find plenty of tutorials on the web offering more details but hope helps you get a better start.

祝你好运!

这篇关于Struts的基本流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆