Chris
Chris

Reputation: 18876

Java Web Architecture

I am interested in putting together a URL Auction research site. It will be structured as a standard [Presentation Layer <-->Business Layer <--->Data Layer]. This site will have an index.html that will allow users to enter a url they are interested in. That index.html will then call a doPost method via servlet which in turn spits out a results page of whether or not that URL is for sale like so:

index.html

<html>
<head>
<title>URL Auction Search Page</title>
</head>
<body>
<CENTER>
 <FORM ACTION="/ResultServlet/Results" METHOD=GET>
   <INPUT TYPE=TEXT NAME="st">
   <INPUT TYPE=SUBMIT VALUE=Submit>
  </FORM>
</CENTER>
</body>
</html>

Servlet:

@WebServlet("/Results")
public class Results extends HttpServlet {
    private static final long serialVersionUID = 1L;
       public static String str="";

    private String businessLogic(String q){
        try {
            str = new compute.URL.GetAvailURI( "https://www.registerdomains.com/auctionAPI/Key:a05u3***1F2r6Z&urlSearch="+q);
            /*more boring number crunching */
            return str;
            }
/*
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
    }
*/
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Results r = new Results();
        String st = request.getParameter("st");
        response.sendRedirect("results/resultActionURL.html?st="+r.businessLogic(st)");

    }

}

However, there will be 2 other links from the results page that I need to process. Namely, a link called WhoOwnsThis.html which takes whois data and geographically maps this information on Google maps. Also, AppraiseResult.html that gives a real time appraisal of the url in question. OK- these 2 pages will take time (very loosely we’ll say 2 sec. ea.) to crunch so I am presenting the user with the results page while I then go on in the background and create the data for each of the other two results pages.

Question- How do I handle the statefulness of these three results pages? My first thought is to create a unique directory each time the two additional results pages are created(WhoOwnsThis and AppraiseResult). Then I can embed the unique dir name as an argument in the results page url so that when they click on the link to the other 2 results pages, the dir name will be pulled from the results page url as a .js var and inserted to get the right page. However, I am also reading up on REST and wondering if that is a better way of handling the state for this transaction. What would industry standard recommend in this scenario?

Upvotes: 0

Views: 95

Answers (2)

Mirko Adari
Mirko Adari

Reputation: 5103

Do you really want to work with such a low level API as Servlets? If you are open-minded look at Play Framework 2.0 and get the same experience as everyone on other platforms enjoy. If not, Spring MVC is a good choice. And if you prefer to just have JavaScript frontend then JAX-RS is a good choice.

Note that Play Framework 2.0 includes it's own class reloading mechanism, but you get the same experience with JRebel in other frameworks as well.

State in general is good to keep in the database, so it will be easy to scale. Java EE 6 Web Profile also gives you stateful session beans. Spring MVC has session scoped beans. Each of them do it in their own way, but as it is such a basic concept, there is plenty of documentation on their site and I'm not going to paste it here.

Have fun and welcome to the era of simple Java :)

Upvotes: 4

duffymo
duffymo

Reputation: 308763

I think the more modern layering is four-tiered:

View->Controller->Service->Persistence.

You can choose between asking the Java EE app server to maintain state for you either in the web tier via sessions or as stateful services in the service layer.

Upvotes: 1

Related Questions