Web MVC Framework-commands and page jumps

Source: Internet
Author: User

For the development of large and medium-sized Web applications that are frequently composed of thousands of associated pages for page connections, such as spider web, how to organize and process page jumps becomes a critical factor in the MVC framework. The reason why struts1 can be recognized is that it basically solves the problem of data and view separation. The reason why struts is no longer "struts" after it is upgraded to struts2, the core cause is that the framework is backward and many places are restricted. One reason is that it cannot properly organize and handle page jumps. Of course, although it was upgraded to struts2, it seems much more rigid than rails and other emerging MVC frameworks.
Easyjweb provides many more flexible functions in terms of page organization and page Jump processing. Many ideas come from the essence of some emerging web frameworks such as spring MVC and rails, it allows you to jump pages with concise code or even code.
In web application development, we often encounter the following requirements:
1. Connect to another page from this page;
2. After the server executes a program, the output is directed to another page;
3. After a program is executed on the server side, the output is directed to another program for further execution;
4. After the server program is executed, select a page to display the user output;
5. Page jump requires strong environment adaptability. For example, if the page is deployed in the following directory and deployed in other context directories, the page Jump can be correctly performed;
6. What's more abnormal, such as the easyjf official website, is that when dynamic addresses are required for access, the addresses displayed are all dynamic. When static addresses are used for access, the addresses are all static, the Java Web server cannot work, and Apache or IIS must ensure normal webpage access.
7. Some users prefer URLs like/user/edit/1 and others prefer/user. EJF? For URLs like cmd = edit & id = 1, we require that no matter which URL style is used to access the page, the connection will become a friendly form that users like.

It can be said that there are few frameworks that can fully meet or take into account the complexity and variety of applications for our people. Some Frameworks, even if providing some of the above functions, are at the cost of writing complex code and configuration files. In easyjweb, these functions are provided and simple call interfaces and methods are provided.
The easyjweb solution is as follows:
1. Use the <A> label.
2. After the server executes a program, the output is directed to another page;
  Returns an HTML page object.
3. After a program is executed on the server side, the output is directed to another program for further execution;
  Use the forward or go method.
4. After the server program is executed, select a page to display the user output;
Use the PAGE method.
5. Page jump requires strong environment adaptability. For example, if the page is deployed in the following directory and deployed in other context directories, the page Jump can be correctly performed;
  Use $ html. URL in the page template, for example, <a href = "$ html. URL ('user. list')"> User List </a>.
6. Transfer different address styles
  Use $ html. forward in the page template, such as <a href = "$ html. Forward '('news. technic')"> cutting-edge technology </a>. In this way, news. EJF? Cmd = technic. In static mode,/news/technic.html is accessed.
7. Traditional and Modern URL style Conversion
  You can still use the $ html. URL or $ html. Forward tag to perceive your url style. For example, <a href = "$ html. URL ('user. add')"> Add a user </a>. Are you using user. EJF? Cmd = lsit. when accessing the application, add user. EJF? Cmd = add. If you use/EJF/user/list to access the application, the connection of the edit button is changed to EJF/user/Add.
  
In the code, you can use the original return New Page () method to return the user's view template. You can also use some shortcuts to flexibly query and redirect views. For example, go, forward, page, and other methods. The code of the action in the example of adding, deleting, modifying, and querying a user is as follows:

Import com. easyjf. Container. annonation. Inject;
Import com. easyjf. Core. Support. query. queryobject;
Import com. easyjf. util. commutil;
Import com. easyjf. Web. webform;
Import com. easyjf. Web. Core. abstractpagecmdaction;
Import com. easyjf. Web. Tools. ipagelist;

Public class useraction extends actpagecmdaction ...{
 
@ Inject
Private userservice service;
 
Public void setservice (userservice Service )...{
This. Service = service;
}
/***//**
* Display the user/edit.html page for adding users
*/
Public void add ()
...{
Page ("edit ");
}
Public void edit (webform form)
...{
String id = (string) form. Get ("ID ");
User user = This. Service. getuser (New Long (ID ));
Form. addpo (User );
}
Public void save (webform form)
...{
User user = form. Topo (user. Class );
If (haserrors ())
...{
Page ("edit ");
Return;
}
Service. saveuser (User );
Forward ("list ");
}
Public void Update (webform form)
...{
String id = (string) form. Get ("ID ");
User user = This. Service. getuser (New Long (ID ));
Form. Topo (user, true );
If (haserrors ())
...{
Page ("edit ");
Return;
}
Service. updateuser (User );
Forward ("list ");
}
Public void Delete (webform form)
...{
String id = (string) form. Get ("ID ");
User user = This. Service. getuser (New Long (ID ));
Service. deluser (User );
Go ("list ");
}
Public void list (webform form)
...{
Queryobject Qo = form. Topo (queryobject. Class );
Ipagelist pagelist = service. queryuser (Qo );
Commutil. saveipagelist2webform (pagelist, form );
}
}

Userservice interface:
Public interface userservice ...{
/***//**
* Query users by ID
*
* @ Param ID
* @ Return
*/
User getuser (long ID );

/***//**
* Save the user
*
* @ Param user
*/
Void saveuser (User user );

/***//**
* Modifying user information
*
* @ Param user
*/
Void updateuser (User user );

/***//**
* Delete a user
*
* @ Param user
*/
Void deluser (User user );

/***//**
* Query user information
* @ Param Query
* @ Return paging information and record set
*/
Ipagelist queryuser (iqueryobject query );
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.