I am developing an Ajax-heavy application, where the user never navigates away from the same page. However, there is going to dozens of different kinds of calls to the server for data and I’m confident this application will be added onto in the future. For each of these calls I’d need to check to make sure the user is (A) logged in (B) has sufficient permissions for their request, and then fill a bean with hibernate, and then convert it to either JSON, XML or an error/login message.
I know this possible with Struts, but is there any advantage to using it when I can just make a custom servlet controller that conceptually looks like this:
Controller extends Servlet
{
status = checkLogin()
if(status == SUCCESS)
status = checkPermissions()
if(status == SUCCESS)
status = validateCommand()
if(status == SUCCESS)
bean = factory()
if(status == LOGIN)
promptLogin()
else if(status == ERROR)
toError(status)
else if(isJson)
toJson(bean)
else
toXml(bean)
}
I feel this would serve my purposes and is simpler/smaller but I am no means a Java expert so I’d appreciate some advice on this. My primary priorities are scalability and maintenance. Maybe there’s a better framework I should use? Thanks in advance!
Alex, the idea to use any framework be it struts2/spring mvc is so take away the common code and let the developer concentrate on the business logic same is the case with you and in future as you have mentioned that it can grow to complex piece so its always better to use any of the existing framework and let them to handle the request flow cycle and you concentrate on the business logic
Additional there is no benefits of re inventing the wheel when its already being developed and well tested by many others.
As you said your primary goal is scalability and maintenance so i believe that its better to use some well known framework for this