JSP vs FreeMarker [closed] - java

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Does JSP provide more flexibility then FreeMarker or is it other way around?
My back-end involves Servlets.
Which one is used under what circumstances?

JSP is going to let you do more things in the view layer, so you might say that makes it more flexible. Things you probably shouldn't be doing though, which one could argue as a benefit for FreeMarker. It would afford you more control over what the view layer can do and force a better separation of concerns.
There's not really any right answer here. You can technically accomplish just about anything with either for your UI. Without more details about your project it's hard to make a recommendation. About the only thing I can say is that you should probably use the MVC pattern. It can be accomplished with either.

My answer would be definitely to go with Freemarker.
Reason is flexibility in a term of usage.
It does not require servlet container, so you can also render e-mails or anything text based.
In a web application it makes possible to create web-modules as jar. Freemarker templates can easily be loaded from classpath (also, spring makes possible to load css/js - static content - from classpath with mvc:resources tag and scan for controllers). So a web module can contain its own templates, static data and controllers.
Freemarker is more powerful in terms of creating custom tags, jsp makes it just a pain. Also, custom tags allow calling back to body parameterized which you will not really be able to do in JSP very easily.
From Freemarker you can still use every JSP tag library available without problem :)

There are several libraries that have been around JSP like JSTL, DisplayTag, etc. that you can use if you choose to go with JSP. With Freemarker, there are not as many of them.
JSP is tailor made for Web pages, FTL is a more generic templating language - it can be used to generate html, plain text, emails, etc.
To pick one, you must consider what kind of tools you have. All good Java IDEs have excellent JSP support. FTL support may/may not be as good.

I believe that you already went for one or the other option by now. Anyway, comment might still be useful for others.
As WhiteFang wrote, using MVC is the only highly recommended suggestion.
If your application is a web based one, JSP would most likely be a better option as it is better known and one can write quite clean presentation code using JSTL (just make sure you don't mix in scriptlets ... all data should be prepared in servlets and passed on to JSPs as attributes). Choosing JSP you bring value to the project by enabling managers to plug-in easily other developers when needed to deliver faster etc.
Anyway, since you already have it on FreeMarker, if the template looks ok already, I wouldn't change it. Rather wait for when you have a business reason to switch. Whatever well designed an application might be, it will eventually need to be partially or even fully rearchitected. As long as you do modular programming, and keep your transformation in an isolated module, you will be able at any time to easily switch to whatever technology you'll see fit (potentially a new one, better than FreeMarker or JSP :) ).
I am usually using FreeMarker for non web applications. Or even in web applications, when I need to generate notification emails for example, which don't need to be web enabled. Otherwise JSP works great so far.
Stef.

Related

Any recommendations for Scalable front end design methodologies (Spring Framework) [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I have some questions from UI folks #java technology
I have recently switched from php to java domain. Though I have good experience in front end theming work with CMS application driven by php.
Since, know i am very new to spring framework, and have developed an understanding with jsp files for the UI aspect.
If you may recommend, assist me or give suggestions... what best design ui practices can be followed to make the design live as consistent looking organism in the enterprise level application.
right now, bootstrap is css framework of choice...and is well adopted into application.
Sharing some details, though I find it very challenging to teach the java developers, the aspect of ui design... apart from their primary task of coding, building the logic from product owner requirements and UI inputs from wireframe screen...
as they are not visually inclined to 'pixel' based aesthetics... i have found interface does not come out well at places...and do not look very polished
and since there is resource crunch of good UI/UX foks who can solve their problems and apart from coding the best interaction in the application, new features ...blah etc.
Though, have started to train them slowly, repeatedly and steadily...on teaching them on how to reuse your css code, write efficient styles and to attain the level of well aligned and well thought placed pixels on screen/viewport.
What best or any training module i can bring on, so that they become self sufficient... for e.g. have been done also
http://slid.es/gauravmishr/introduction-to-css-for-jsp-developers
Will like to know your recommendation and thoughts, so that design scalability can be achieved.
Over to java ui/ux gurus :- )
maybe you should give Asual's Summer a try. It is a presentation layer library for Spring MVC. It allows you to reference resources from jars and thus makes modularization really easy. Most importantly for me, you write simple html5 with some custom tags and el expressions instead of JSPs. It also has support for resource caching and compression. Finally, you can prepare html templates to include in your views, thus increasing core reusability. I have used it extensively with twitter bootstrap and it works great.

How to implement a servlet/applet combination with two different functions? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I've been tasked with creating a Java web application that consists of two pages, a "Draw" page and an "Evaluate" page. I'll be developing in Eclipse.
The "Draw" page will facilitate the following process:
Take user input from a form
Using a Servlet, build a model in the background
Send the model to an Applet (probably via JSON) on the client-side to be rendered visually
The "Evaluate" page will:
Take user input from a similar form to build a similar object (same class) using a Servlet
Run a the model through an algorithm on the Servlet, and display the results on screen.
The pages can be relatively independent.
My question is, exactly how should I go about implementing this combination?
I'm familiar with Servlet development and the Spring MVC/Webflow framework, but in no way an expert. However, I'm guessing Spring would be overkill for this simple application, and I've never implemented a Servlet that has more than one major function.
Should I make an HttpServlet that just has conditional logic in the doGet/doPost methods, and performs an operation based on the request's URL?
Should I make two separate Servlets?
If so, would I make two separate projects in Eclipse, or just one project with two Servlets registered in web.xml? Should I do something totally different?
I'm not looking for code, but just would like to have a stronger understanding of how to approach this type of application.
I'm going to provide an opposing view to that of Dmitri's. I think its great for people to know how to write plain servlets but when it comes to writing code for a business I think you'd be better off using Spring MCV. The main reasons are:
you already have experience with Spring MVC, so no learning curve
although the requirements seem straight forward, my experience is that web projects like this quickly grow way beyond their initial specs, at which point you'll be wishing you'd used Spring MVC
You will have to code and maintain the features in a servlet which are normally handled by Spring MVC - I love the saying: they have solved problems that you haven't even thought about yet.
every line of code you write has the potential to be buggy, by reducing the amount of code you write you reduce the risk of bugs
Spring MVC is designed in a such a way that you can use as little or as much of the features that you like/need. With annotations, you can get a simple app up and running with a surprising small number of lines of code/xml
testing is much easier with Spring MVC
Spring MVC follows a convention that other programmers already know. If you leave your job, then someone can pick it up very quickly. OTOH if you code a simple servlet, you could do it a number of different ways that could make it harder to maintain for someone else
with modern hardware/OS, the extra memory/overheads that adding Spring MVC adds to you project is negligible - we no longer run our servers with 128KB of memory but some people still have a mindset that we do. If in doubt benchmark it, don't early optimise!
Spring (or any other MVC) framework is definitely overkill for this, servlets will do just fine.
Make sure all of your actual logic is in a separate class, all your servlets should do is apply whatever processing needs to be done to read the user input, and call the appropriate methods on your service class. Basically keep the web-specific parts minimal.
Whether it's two separate servlets or one that switches on the request path doesn't really matter. I'd use two separate ones, since mapping requests to methods is pretty much what servlets are designed to do.
You do not need separate projects in Eclipse, just define the servlets in web.xml (or with annotations if on Servlet 3.0).
It sounds like you're on the right track.

What should I know before learning Spring? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Opinion-based Update the question so it can be answered with facts and citations by editing this post.
I've been learning Spring and I'm really liking what I'm learning, but feel ill-equipped to do anything at the moment. I know Java really well, I'm ok at ant, but I don't know anything about: J2EE, JSP, Servlets, Tomcat, Maven, Hibernate, JPA, and I've never made any kind of website using Java (I've made lots of applications in Java, but all websites I've made were using PHP).
Should I cement some of my knowledge of the "basics" or should I keep slogging away at Spring?
Spring is a monster. It all depends on what part of Spring you are interested in. A good starting point would be the Dependency Injection container, which requires none of the technologies that you are unfamiliar with (the ones from your question).
If you are interested in learning Spring MVC (which it sounds like you might be based on the technologies you mention), I would recommend learning the basics in these (again from your question):
Servlets
JSP
Tomcat (or another web application container)
For Spring MVC I would also look at the idea of RESTful web services.
You can find a (likely) comprehensive list of Spring projects at this link.
I would recommend three things:
Lots of Reading => Spring Documentation in a Single Page
Lots of Coding => You can start off by getting an example Spring / Hibernate project. And then use Spring Tool Suite, which includes many interactive tutorials, and template projects that just work without any coding at all.
Find a Spring User Group next to the place you live. If there is no such group => create one!
It is totally ok that you don't know JSP / Servlets / Tomcat / J(2)EE / etc. Extremely smart people who, for example, write Linux kernel (which is a lot more complex) may not know it as well. The beauty of Spring is that going through it, and reading about best patterns and approaches you'll get all the above. No need to learn J(2)EE separately. Spring is J(2)EE of today.
For a good enterprise developer, I would recommend
a) very very good core java ( including collections, jdbc , threads)
b) servlets
Then I think you can start diving into spring.
If you want to accomplish something quickly to start with, definitely look at JSPs. A JSP is basically an HTML document with some special <% %> tags where you can just shovel in java. It's really entertaining, although nothing you'd want to use for a large-scale application.

JSF or MVC with Servlets/JSPs or other frontend frameworks? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm working on development of a social web application using Java. I need to develop the frontend/GUI of my application for web browsers.
I'm wondering what is the better strategy to do frontend development, whether using frameworks like JSF 2.0 & like OR simply following MVC approach with servlets and JSPs ?
As I have heard JSF really makes the development simpler but also the learning curve is not too low, so is it worth learning JSF or I should prefer to directly proceed with servlets/JSPs ?
I'm new to web applications development using Java & I've almost completed writing the business logic for the application.
Please justify your answer on the basis of following parameters:
Performance & costs
Ease of Development & Time (considering the learning time as well)
Future Maintenance of code
Any other parameters you consider important
Update (07-09-2012):
I finally went with JSF-2.0 & have no regrets till date. Learning curve is not steep. It's easier & development is fast with component libraries like Primefaces. There are some costs as to state saving but those things can be handled intelligently. Community is big & things are well documented now. Hopefully, in near future Stateless JSF is also coming which will boost JSF with extra high performance.
For a hobby webapp, homebrewing some MVC framework is not bad. It's a nice learning exercise tour. However, it will bite you on the long term, for sure if you publish on the web and it becomes popular. Most of existing MVC frameworks are very well thought out. Most of the unforeseen caveats are taken into account. The sole framework API is well maintained and documented by a third party.
Also, whenever your webapp becomes popular and you need more developers to work on it to fulfill the enduser requirements/wishes, it's easier to find someone who's already familiar with an existing framework. With a homebrewed and possibly buggy MVC framework, you'll likely find less developers who are eager enough to dive into another learning curve before taking over the maintenance which they'll probably never reapply on their future jobs/projects.
This does not specifically apply on JSF, but on every other existing and popular MVC framework as well, such as Spring MVC. As to JSF in general, well, I've written a lot about it before here. Here are some good starting points to read the one and other about it:
JSF versus plain HTML/CSS/JS
JSF adoption and popularity
What are the disadvantages of JSF 2.0?
For modern web apps like yours, and if your responsibility is the UI, you really don't want any "abstraction layer" stand between you and your html/css/javascript. Don't use any "component" framework.
I have heard JSF really makes the development simpler
Did you hear that from real webapp developers who actually used JSF in real products? Or just JSF committee patting their own backs? Or some old timers' wishful thinking that they don't need to learn the darn javascript?
If you choose JSF, please report your experience back to us after you shoot yourself out of frustration.
It's better use some MVC framework.
You can use either component based framework:
JSF = mostly standard, but its hard to learn and a lot of people don't like itTapestry = quite big and probably good framework
Wicket, GWT - smaller component based frameworks, handy, powerful, smart, but I haven't used them yet
Or you can use request oriented framework.
Spring MVC, Struts 2 = They are very similar. Spring MVC have probably better documentation
Struts - I do NOT recommend this, when you can use Struts 2, or Spring MVC - you can trust me in this point
Each framework have its pro-and-con it depend on situation and your knowledge. I cannot give you single-valued answer.
Spring MVC is very easy to learn and if you have a simple web app and you want to save your time, its better than JSF.
However if your web app is not so simple, JSF beats Spring MVC by far. Its model is more complicated, but it is much better structured and it is widely supported, so that you don't have to reinvent the wheel again in most of the cases. Complex gui can done with JSF with less effort.
You might want to consider Tapestry 5 if you're exploring options. We've been happily using it for many years on a large project in the social media space. It's an easy to use MVC framework that's component based. We're able to develop rapidly with it, especially now that we've built up a lot of our building blocks.
Learning time is probably on par with ramping up on any new framework. I'd perhaps say it's less than JSF and more than Spring MVC, though it really depends on what you're already familiar with and how deeply you use things. I put together a very small project on github a while back to get started with Tapestry 5 quickly, if you're interested it's tapstack.
As for long term use of a Tapestry based application, it has served us well. Maintenance of the code has been much better than when were using JSP. It's very stable as well. We've served billions of page views through Tapestry without any major problems.
On the downside it is less common than some other web frameworks. It is definitely a little different too. We feel it's worth it though, and refreshing to work with. Ultimately it's going to depend on what you need and what you feel works best for you. Best of luck with your decision.

I need a simple rules engine, I think? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I need some advice on the best approach to solving this problem.
I've researched DROOLS, Java Rule Engine and a few others. All of these are powerful, and have good things about them. I don't know which (if any) will be the best choice for me.
I have one business object. (simplified for demo)
Person
firstName:String
lastName:String
departMent:String
hireDate:Date
I need to write an editor in a web application that will allow for complex rules to be built around these fields. I need to support complex nested AND/OR logic. I just need basic operators, and the rule should simply evaluate to true or false. If the rule evaluates to true or false, one action will occur respectively.
For example,
firstName CONTAINS "value" AND
(lastName EQUALS "input" OR department
CONTAINS "input")
I had thought, maybe I should just write my own parser and evaluate the logic in my own code. I don't know what to do, any advice or links to something to read would be greatly appreciated. Is there a specific design pattern I could research?
How would you solve this problem? One reservations about the rules engines is that maybe they are too complex for just a simple problem?
This is not an yes/no question, but I can probably share my experiences, and hope it helps.
I have used DROOLS quite successfully in a few projects. Apart from some cases (another team had issues with DROOLS under heavy load,) DROOLS is quite an useful library.
I built an application which:
1. read input from a source
2. chose the next action based on the input from a set of available operations
As trivial as it looks, it needed to be very flexible:
1. The input was a variable set of name-value pairs, names not predetermined.
2. values, presence/absence of certain name/values (based on occurrence/absence of events), trigger different actions.
3. The business rules can change while the application is running.
Maybe there are better solutions, but for better or worse, I ended up using DROOLS. I developed a BPEL in which the decisions are made by the DROOLS component. The DROOLS component internally reads the decision making rules from a Microsoft Excel spreadsheet. It rebuilds the rules if there is a change in the file.
Now the domain experts change this spreadsheet when required, and we do not go through painful deployments!
If you want a sophisticated UI, DROOLS Guvnor is a readily available web-application (with rich UI,) which would help your domain/subject-matter experts to build rules and store them in a database.
The Drools documentation talks about when to use a rules engine. http://downloads.jboss.com/drools/docs/5.1.1.34858.FINAL/drools-expert/html_single/index.html#d0e181
From the docs...
The shortest answer to this is "when
there is no satisfactory traditional
programming approach to solve the
problem.". Given that short answer,
some more explanation is required. The
reason why there is no "traditional"
approach is possibly one of the
following:
-- The problem is just too fiddle for
traditional code.
The problem may not be complex, but
you can't see a non-fragile way of
building a solution for it.
-- The problem is beyond any obvious
algorithmic solution.
It is a complex problem to solve,
there are no obvious traditional
solutions, or basically the problem
isn't fully understood.
-- The logic changes often
The logic itself may even be simple
but the rules change quite often. In
many organizations software releases
are few and far between and pluggable
rules can help provide the "agility"
that is needed and expected in a
reasonably safe way.
-- Domain experts (or business analysts)
are readily available, but are
nontechnical.
Domain experts often possess a wealth
of knowledge about business rules and
processes. They typically are
nontechnical, but can be very logical.
Rules can allow them to express the
logic in their own terms. Of course,
they still have to think critically
and be capable of logical thinking.
Many people in nontechnical positions
do not have training in formal logic,
so be careful and work with them, as
by codifying business knowledge in
rules, you will often expose holes in
the way the business rules and
processes are currently understood.
When not to use...
As rule engines are dynamic (dynamic
in the sense that the rules can be
stored and managed and updated as
data), they are often looked at as a
solution to the problem of deploying
software. (Most IT departments seem to
exist for the purpose of preventing
software being rolled out.) If this is
the reason you wish to use a rule
engine, be aware that rule engines
work best when you are able to write
declarative rules. As an alternative,
you can consider data-driven designs
(lookup tables), or script processing
engines where the scripts are managed
in a database and are able to be
updated on the fly.
I would suggest your own parser. In this context why can't you serialize the object and use AJAX to validate it in the back end? It then seperates the validation logic from the UI.
I would take a look at some sample rules engine interfaces and see which ones I like. You can look at web based email rules interfaces to get some ideas. If you really need a simple rules engine, you just need to create a good interface, and then you can send the rules to the server with javascript.
Probably not. You need a decent domain model. Not one where your objects are just data placeholders. Are your users likely to be able to understand and use such a complex rules system, and wouldn't those that do prefer just programming in java, where they have proper encapsulation and refactoring support? Rules systems only work with simple rules on a restricted domain, where you can explain people not trained as programmers how to build them. And don't forget rules building is just programming, so you still need version control, tests, and don't want globals.
Wouldn't Jython be usefull?
Each expression/complex-rule could be the body of a function.
So the user provides the body, and your code puts the function spec around it, and then execute it.
You can also put any Java objects / variables of your own into the jython context to be used in your script/ function body.
Then you have a standardized, extendable widely used language at your fingertips.
But i think the Jython editor could be a challenge.
Have you tried JBehave?
JBehave is a framework for Behaviour-Driven Development (BDD). BDD is
an evolution of test-driven development (TDD) and acceptance-test
driven design, and is intended to make these practices more accessible
and intuitive to newcomers and experts alike. It shifts the vocabulary
from being test-based to behaviour-based, and positions itself as a
design philosophy.

Categories

Resources