— Здесь вы сможете найти отзывы по банкам из таких городов
    как Москва, Санкт-Петербург, Новгород и многих других

Helps view a good example product lessons, motion, servers webpage, and mapping.

Helps view a good example product lessons, motion, servers webpage, and mapping.

By promoting

Place for ADS
these ponents, we’re breaking up the work flow into three famous issues: the View, the product, in addition to operator. Dividing concerns makes it easier to deal with programs while they bee considerably plex.

If you want, turn up the Java IDE, and enter the laws once we get.

This information thinks youve pleted the How To Create A Struts 2 internet Application guide and also have a working fundamental Struts job. The instance rule for this guide, helloworld, exists for checkout from the Struts 2 GitHub repository at struts-examples. The example projects use Maven to deal with the artifact dependencies also to develop the .war data files.

The Laws

Allows customize the basic-struts task to add the following:

  • an unit class to save our very own message
  • a see that presents our message
  • a motion class to behave just like the operator
  • a setting that ties anything together

The Struts 2 individual email list is a fantastic destination to see help. If you should be having difficulty getting this application to be effective browse the Struts 2 subscriber list. If you dont look for a remedy your challenge, blog post a concern throughout the subscriber list.

1 — Create The Product Lessons MessageStore.java

Produce the MessageStore course in src/main/java . Definitely note the package report below.

Observe that in the rule shown beneath the JavaDoc ments include omitted. In the download sample, JavaDoc ments come.

MessageStore.java

Note the employment of the public getter solution to allow use of the private information String feature. The Struts 2 framework necessitates that items you intend to show into the see ( HelloWorld.jsp ) stick to the JavaBean-style events.

Step 2 — Create The Actions Class HelloWorldAction.java

We need an Action course to act since Controller. The Action course reacts to a user actions (in this instance that activity should be clicking an HTML hyperlink and delivering a certain Address into Servlet container). More than one with the Action classs practices is accomplished and a String result is returned. Based on the worth of the result, a specific view web page (within example that see web page are HelloWorld.jsp ) are rendered.

Note the plan and significance comments down the page.

HelloWorldAction.java

The Struts 2 framework will generate an object from the HelloWorldAction course and name the execute process in response to a people motion (clicking on one of the links that directs a specific URL to your Servlet container).

Within sample, the execute approach creates an item of class MessageStore and then returns the String continuous PROFITS .

Note furthermore the general public getter way of the private MessageStore object. Since we would like to make the MessageStore В object offered to the scene webpage, HelloWorld.jsp ,В we should instead stick to the JavaBean-style of promoting getter and setter means in which recommended.

3 — Create The View HelloWorld.jsp

We require a server web page to present the content which kept in the product lessons MessageStore . Produce the below JSP within the folder.

The taglib directive informs the Servlet bin that page might be utilising the Struts 2 tags hence these tags will be preceded by an s .

The В label showcases the worthiness returned by phoning the method getMessageStore В associated with the HelloWorldAction В operator class. That approach returns a MessageStore В object. With the addition of the .message В on the messageStore a portion of the worth feature the audience is advising the Struts 2 structure to name the getMessage В technique of that MessageStore В object. The getMessage В approach to course MessageStore profits a String. Its that String which is demonstrated of the В tag.

Better find out more about labels in the next information. Look at Struts labels for additional information about tags.

Step 4 — Add The Struts setup In struts.xml

We need a mapping to tie the URL, the HelloWorldAction В class (operator), and also the HelloWorld.jsp В (the view) with each other. The mapping informs the Struts 2 framework which course will answer the customers motion (the URL), which technique of that lessons are accomplished, and exactly what view to render on the basis of the String benefit that method profits.

Modify the struts.xml file (in Mvn task that file is in the src/main/resources folder) to incorporate the action mapping. Put the action node (motion term=»hello» ) involving the starting and shutting bundle node, after the experience mapping because of the title=»index» . Their plete struts.xml need to look like:

struts.xml

Step 5 — Produce The URL Action

Allows include an actions URL inside index.jsp (discover src/main/webapp folder) so the consumer can select a web link to inform the Struts 2 framework to operate the perform approach to the HelloWorldAction course and render the HelloWorld.jsp view.

1st include the taglib directive at the top of the jsp . Further incorporate this p label

following title tag. Your new index.jsp will want to look like:

index.jsp

The Struts address tag brings the Address with an action of hi. The hello activity was mapped for the HelloWorldAction class and its execute means. As soon as the user clicks in the over URL it will cause the Struts 2 framework to perform the perform approach to the HelloWorldAction class. From then on means returns the String achievements (continuous SUCCESS ), the scene web page HelloWorld.jsp can be made.

Move 6 — Build the combat document and Run the application form

Perform mvn jetty:run to perform the application.

Click on the Hello business website link and you need to have the HelloWorld

How Code Really Works

  1. The bin obtains on the internet server a request the source hello.action . According to research by the setup packed from the web.xml, the container finds that all demands are routed to org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter , like the *.action desires. The Struts make And Execute filtration is the access point to the platform.
  2. The platform actively seeks an activity mapping named hello, and it locates that the mapping corresponds to the course Hello business motion . The framework instantiates the experience and calls what escort service Oakland perform strategy.
  3. The execute way brings the MessageStore item and profits PROFITS (= «success» ). The structure monitors the action mapping observe exactly what webpage to weight if ACHIEVEMENTS is came back. The structure says to the bin to give since reaction to the consult, the reference HelloWorld.jsp .
  4. Just like the web page HelloWorld.jsp is being prepared, the tag calls the getter getMessageStore associated with HelloWorld actions immediately after which calls the getMessage associated with MessageStore item came back by getMessageStore . The label merges the value of the message attribute inside reaction.

What things to keep in mind

The platform utilizes steps to undertaking HTML forms and various other requests. The Action course return a result-name like TRIUMPH , MISTAKE or INPUT . According to the mappings crammed from the struts.xml , certain result-name may select a page (such as this sample), another action, or other internet source (picture, PDF).

Внимание! Всем желающим получить кредит необходимо заполнить ВСЕ поля в данной форме. После заполнения наш специалист по телефону предложит вам оптимальные варианты.

Добавить комментарий