Implementation method discussion in a small web project

xiaoxiao2021-03-06  42

Nova http://www.jdon.com Oct 14, 2004 10:51 AM Reply

Recently, it is maintained for one of the other people's web projects. Seeing this implementation: 1. Only a Controller's servlet class 2. A service interface 3. Some of the class Controller classes that implement the service interface are responsible for controlling, dynamically generating business logic classes. The instance (all classes need to implement the service interface), then assign values ​​to the web side by httpservletRequest.setttribute ("UserList"; for the web side, the specific section code: Controller class (Extends httpservlet)

protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// service name, example for packagename.ServiceName String serviceName = request.getParameter (Constant.SERVICE); if (serviceName == null) throw new ServletException ( "There is not service parameter ")! [service =?]; String targetName = request.getParameter (Constant.TARGET); // the targeted file name, example for /fileName.jsp if (targetName == null) throw new ServletException ( "There is not target parameter! [target =?]"); ServletContext servletcontext = getServletContext (); try {// TODO: hashmap to reduce the generated instance Class serviceClass = Class.forName (serviceName); Service service = (? Service) serviceClass.newInstance (); service.execute (request, response, servletcontext);} catch (ClassNotFoundException classnotfoundexception) {throw new ServletException (classnotfoundexception.getMessage ());} catch (IllegalAccess Exception illegalaccessexception) {throw new ServletException (illegalaccessexception.getMessage ());} catch (Exception exception) {throw new ServletException (exception.getMessage ());} forward (request, response, targetName);}

Service interface

public interface Service {public abstract void execute (HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, ServletContext servletcontext) throws Exception;} class implements a service (corresponding to traffic class)

public class StartService implements Service {public void execute (HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, ServletContext servletcontext) throws Exception {// test data List userList = new ArrayList (); httpservletrequest.setAttribute ( "USERNAME", "TestUser"); httpservletrequest.setAttribute ("UserList", UserList;}}

JSP page file

<% String username = (string) Request.GetaTribute ("username"); list userlist = (list) Request.GetAttribute ("UserList");%>

When visiting:

/service.controller?service=startService&target=/startpage.jsp

I want to know now.

1. How about this implementation? Why do you do this, what benefits?

2. Is there any need to save more objects with HashMap to avoid more objects

// TODO:? Hashmap to reduce the generated instance Class serviceClass = Class.forName (serviceName); Service service = (Service) serviceClass.newInstance (); service.execute (request, response, servletcontext);

3. Do you have a good similar program (just for small web projects, don't say it with Framework)

Thank you!

Re: A small web project implementation method discussion Time: OCT 19, 2004 9:51 AM

Reply Poster: Banq Post article: 3985 / Self -: Shanghai / Registration time: 2002-08 This is actually a Command mode implementation, Service is a Command interface, this small system has a MVC mode basis, I think it is a good code. Two questions about you:> 1. How about this implementation? Why do you do this, what is the benefit of this is mainly the benefits of using the Command mode, generally accepting the external processing command in the server, which is a habit. This is a habit, the main advantages are: 1. Clear, expand, easy, Add a new service as long as the service is inherited. 2. Good performance, because the server is directly submitted to specific service processing, without other intermediate delay procedures. > 2. The generated service class object is not necessary to save with HashMap to avoid more objects. This is mainly to improve performance, because NewInstance generates instances are slower than New, so after the first generation, save, second time There is no overhead created, of course, it is recommended to use the object pool Pool to replace HashMap. There are three options in the object pool: 1. Use the POOL components of Apache. 2. Indirect use of Apache Pool.3 through the Spring's AOP interceptor. Turn Service into EJB's idomy bean. Re: Implementation method in a small web project discussion Time: NOV 8, 2004 2:44 PM

Reply Poster: Xchesenlin Published Articles: 30 / Since: Hainan Province Qionghai Tower Tower Hongzhuang Village / Registration Time: 2003-09 Nice Post ,, concerned .....

Re: Implementation Method in a small web project Published: Nov 13, 2004 7:24 PM

Reply to: Luzhong Zhengqi published article: 120 / From: China Beijing / Registration time: 2004-09 is good, it is good, it is a little, the metadata, good use, this is the vertical direction, no use Metadata lateral control. You this action, very similar to me, but didn't reach AOP, but it is too fast. A little bit. Ha ha.

Re: Implementation method in a small web project discussion Time: NOV 13, 2004 7:26 PM

Reply to the publication: Luzhong Zhengqi published article: 120 / Self: China Beijing / Registration time: 2004-09 In addition, if you use Struts, combined with JBuiderx, etc., you can "industrially".

Re: Implementation Method in a small Web project Published: DEC 1, 2004 1:02 PM

Reply to the publisher: WZW9258 published article: 6 / Registration time: 2004-11 I don't even get a lot of service implementations

RE: Implementation Method in a small Web project Published: DEC 2, 2004 3:30 PM

Reply Poster: Yulchina Post article: 2 / Registration time: 2004-11 This article is not a collection function ~ This article is really good!

Re: Implementation method in a small web project discussion Time: DEC 9, 2004 2:37 PM

Reply Poster: Brokendoor Post article: 6 / Registration time: 2002-09> Recently, you have maintained a web project of someone else, see this implementation:> 1. Only a Controller's servlet class> 2. A service interface> 3. Some MVC frameworks that implement the class of the service interface are so real. I personally think that even a small project, use the mature framework should be preferred. Personal recommendation: Turbine or Webwork. I have made a JWORKS extension, used to compatibility with the Turbine and Webwork framework, interested friends can look at it, mention valuable comments. http://www.softme.org/jwiki/v_1.2.1/jwiki.jsp?topic=jWorksre: Implementation Method in a small web project discussion Published: DEC 11, 2004 5:33 PM

Reply to the publisher: Edge people published articles: 2 / Registration time: 2004-12 found

Re: Implementation method in a small web project discussion Time: DEC 11, 2004 5:33 PM

Reply to the publisher: Edge people published articles: 2 / Registration time: 2004-12 found

Re: Implementation method in a small web project Published: DEC 13, 2004 12:53 AM

Reply Posted by: yangkun24 Posts: 19 / Registration time: 2003-08 My company uses ASP to do projects, and use a similar way. First, there is an Ibusiness_Run method in a framework.ibusiness interface, then each leaf face should be a "business class", all "business classes" are inherited Framework.ibusiness interface, and only Ibusiness_Run methods, when Ibusiness_Run methods are running After completing, all the information of the leaves is present. In these "business classes", the REQUEST / RESPONSE and other interactive objects are created from the parameters of the ibusiness_run method. . . I don't know what everyone thinks?

Re: Implementation method in a small web project Published: DEC 29, 2004 1:47 PM

Reply Poster: Yulimin Post article: 9 / Registration time: 2004-06 YAWL's workflow engine is also a bit similar to this.

Re: Implementation method in a small Web project Posted: Jan 11, 2005 9:32 AM

Reply to the publisher: Siberian published article: 15 / Registration time: 2003-07 People think that since it is your own project, you don't have to use a command pattern. In accordance with your own processes, you have to save much more. Other program development is much easier. From the easiest way.

Re: Implementation method discussion in a small Web project Posted: Jan 11, 2005 9:35 AM

Reply to the publisher: Siberian published article: 15 / Registration time: 2003-07 Assignment program to do value objects, the page is just getting it. This is relatively easy to convert to C / S. If there is no such request. This is still more straightforward.

转载请注明原文地址:https://www.9cbs.com/read-61264.html

New Post(0)