Is it possible to substitute pure html and js for JSP? - java

I'm learning JavaEE now and I kind of feel that JSP can be messy... I hate to mix my Java code with HTML... I want to separate the front end view and Java code as much as possible.
I've ever tried Twitter Bootstrap and I find it amazing. Is there any way that I can use HTML and JS(maybe some framework like Bootstrap) to substitute for JSP view technique? How should I accomplish the data interaction?

Yes, that is what all the kids are doing. You use REST.
You can see an example of just that in this Quickstart.

Strictly speaking, no. JSP is a server-side technology. That means that the code you write in the page is executing on your server in the environment you have set up there. HTML and JavaScript are client-side technologies; the code you write in these languages executes in the web browser of the people viewing your website. Neither technology is a complete replacement for the other; both are needed.
Even if you move more of functionality out of JSP into JavaScript (a "heavy client" implementation), you still need some server technology for your JavaScript to call to. You could get rid of JSP by moving some of the server functionality into other technologies: webservices (JAX-WS, Axis, etc.), RESTful services (JAX-RS, ApacheCXF, etc.), or straight up synchronous web-pages. But the point is regardless of what you use or whether you get rid of JSP entirely, you still need a server-side technology.

Related

How can I convert an Applets application into an Web application using JSP and Javascript?

I have a project that is built on Applets and that also comprises of Corba calls to backend (which is in C language). Now I need to remove Applets and convert it into JSP and Javascript combination. But the code seems to be complex as it also consist of backend calls. I am facing problem in figuring out what is to be converted in JSP and what in Javascript.
If I convert all the applet logic in Javascript, how will I pass the javascript data to the Java objects to pass it as input for corba calls.
I can't implement all the logic in JSP as the existing logic depends on the dynamic change of data by user.
I tried various links but couldn't find the proper solution to my problem.
I read somewhere that Google Web Toolkit (GWT) might help me converting Java Logic to Javascript, but couldn't figure out what exactly needs to be done for that.
Can anyone guide me how should I start and what exactly should I do to complete my project?
First the bad news. There is no generic and magic solution that can convert your legacy (as you are describing it) into modern n-tiers web application.
I can suggest you the following steps.
decide what kind of client and server side technologies you are going to use and learn them to become familiar enough to start coding.
learn your legacy code and re-design it. Decide which parts of the code must be re-written, what you can use as-is and what you have to change and/or re-package.
To choose client side technology try to search for "client side javascript frameworks" or something like this. Popularity of GWT that you mentioned is going down now. The most modern framework these days are AngularJS.
Concerning server side technologies I personally prefer Spring but you can take a look on Guice and EJB too. You can also implement whole server side as as collection of servlets. It is up to you.
Start learning this amazing world and come back with more concrete questions. Good luck.

Java Servlet web development questions

I have been doing web development with PHP for the last few years, and like a lot of people, I have a strong dislike for PHP. I also have done lots of Java development, but never web development. Having a good knowledge of Java, I decided I would try web development using JSP. I have read a few articles but I am not fully "understanding" it. My first question is, what is the difference between a JSP (Java Servlet Page) and a servlet? Is a JSP not simply a file that contains a servlet and HTML? My second question is can Servlets interact with HTML elements as easily as PHP? Can I check for HTML form input using POST/GET etc.
I was also wondering if Servlets could use "native" java code. By this, I mean can I use the same code that I use in desktop applications/use the same methods and classes that I have already made. What I am trying to get at is, can servlets do (almost) anything that a desktop application can do. Can I access the servers file system to delete/ modify files? Can I use third part java libraries in my JSP? If someone could clear this up for me that would be great! Thanks in advance!
JSPs are a templating language for generating servlets. Every JSP is compiled into a servlet. Everything you can do with a JSP can be written as a servlet.
No, a JSP does not contain a servlet. It's compiled into servlet Java code and then that's compiled into Java byte code.
Servlets can interact with all HTML elements. They're HTTP listeners.
I would strongly advise you not to use native code in a servlet.
You should not be putting scriptlet code into JSPs. That's a 90s style of writing JSPs that's been discredited. Use JSTL. JSPs are for display only.
At a basic conceptual level:
JSPs are similar to PHP in that they provide server-side mark-up scripting to standard HTML pages, allowing for dynamic content within a page. The language a JSP uses is similar to HTML, but it is not valid HTML without being pre-processed by a web container like Apache Tomcat. A JSP can contain Java code, although due to separation of concerns this is often discouraged in large systems.
Servlets are separate files written entirely in Java and are used to process actions requested by the client. The requests sent to a servlet can take the form of any HTTP action type, i.e. GET/POST/PUT/etc. A servlet can technically do everything (and more) that a JSP page can do, but the mark-up language that JSP provides is more suitable for working on the presentation layer.
As an example: you may have an HTML form in your JSP that you POST to a servlet, which might then use the posted form data to send a secure email. Once the email has been sent, the servlet may redirect you to a success/failure page, which in turn could be another JSP page. More recently Javascript has become a more common way to interact with servlets, using the XMLHttpRequest API.
Take a look at this guide, particularly the diagram provided.

Integrating Javascript Frameworks with Java Web Frameworks

I have what I think might be a strange question to ask.
Recently I was playing with some java web frameworks (jsf with primefaces) and I noticed that it's quite good at handling form data or when you play along with the jsf components. I also did a project using grails and again it was useful for form data.
But the moment you want to do something which requires a little deviation; then I found myself doing weird things (examples are tag clouds with large strength values using primefaces and single page webapp forms with grails).
This resulted in some very messy html+javascript code for my grails things(which I blame on my inexperience with javascript). This was done because I was using expression language (grails in this case) to populate some of the javascript. The worst part was that I had a bunch of custom javascript code inline with my server pages (I could of refactored a little out but I think one would still have alot of javascript calls inside a single page).
So now to the question(s) :)
[main question] Are there any resources that demonstrates how to design or at least implement maintainable javascript with server pages (gsp, xhtml, etc) ?
The reason is that I find that there are some neat javascript frameworks, but using them with server pages seems a bit unnatural if one takes into account the expression languages for server side frameworks? Unless it's normal to do this type of thing :) ?
Are there appropriate frameworks for Single page webapps using java?
My current answer is that GWT, Vaadin (based off GWT) and perhaps JavaFX qualify. Maybe ZK, Flex and (Grails/Roo + Flex/GWT) also qualify as well?
Are java web frameworks still useful for presentation layers?
My current answer is that they might be when you are dealing with portal type webapps or Web 1.0 apps for lack of a better word. The other case is that they could be when you use alot of role based security and you want to filter things out based on roles, but even that has counter arguments.
My other answer to this is that it might be better to use a java server to provide your web services and then rely on something else to do the front end?
This might be OP, but for single page apps, it's easier to serve up data from the server via JSON(P)/XML/whatever and then use things like Backbone to process and modify the view(s) accordingly. That way, the server can use REST/SOAP/websockets/whatever, and the browser app becomes a full-fledged app.
I haven't actually done this, so don't quote me, but I imagine that it should make sense.

My website is built on Java Server Pages (JSP) - can I use Joomla still?

My website is built on JSP and Java Servlets. Html, Javascript and CSS (limited) is contained within my JSP pages as well.
I recently started looking into Joomla. I have quite a bit to learn yet...
I understand that Joomla is based on PHP.
[ I don't know anything about PHP, but I've read that knowing PHP is not really necessary in order to use Joomla. Do you agree? ]
I have some questions about Joomla -
1) The code that Joomla generates, is that in PHP? or Html? Perhaps a combination of both?
2) How, if possible, can I integrate my JSP code into what Joomla generates?
-- or do I need to integrate the Joomla code into my JSP code?
I have a fully functional website designed in JSP and Java - but after seeing the layout/design that can be accomplished with a CMS, such as Joomla, I want to know how I can 'convert' my site, or 'integrate' it, and still keep it running under JSP and Java.
Joomla is written in PHP. It generates the HTML files which are output to the browser. As far as I know, you'll need PHP to use Joomla unless there's been some sort of JSP port for it (which is highly unlikely).
Simply, Joomla IS PHP, and it generates HTML code which the browser reads.
Also, a CMS has nothing to do with layout/design, a CMS is simply that, a Content Management System. They are usually designed to be used as the actual website itself, the user just picks a theme and inserts content.
If you are looking to keep the server-side business based on JSP, JAVA and upgrade the layout using Joomla you are facing a lot of PHP programming and the result would not be great in terms of performance. It is easier to migrate to a solution based on JSF and Facelets.
Joomla is written in PHP ans as with every other server side webbased view/template technology (including JSP), it just generates HTML/CSS/JS (a webbrowser doesn't understand anything else anyway).
If the sole requirement is to have a webbased blog engine with a CMS in Java/Servlet, then checkout Hippo. It's similar to Wordpress/Joomla (although less eye-candy imo).
You could check out Quercus from Caucho which allows you to run PHP applications in a servlet container. I believe they support Joomla though I'm not sure which versions.
Possible solution or answer is that you will need complete rewriting.
You can use Joomla for the web content and JSP for the front end of an enterprise application. Integrating external content in Joomla can be done in many ways, for example, you can embed pages in Menu items, AJAX calls to retrieve content from your JSP pages -either in html or in another format (JSON or XML).

How does Direct Web Remoting (DWR) work?

How exactly or what exactly does Direct Web Remoting (DWR) do?
While I have already gone through the official site http://directwebremoting.org/
I wanted to understand in simple language..
Specifically I have following questions;
1. While engine.js is standard Javascript library, how exactly does it help in including that in our app ?
2. What is so special about DWR that cannot be done by normal Javascript / AJAx combination?
Thank you.
OK, I've only had a brief look at DWR and I was wondering the same thing. As far as I can gather DWR builds and includes on your page some javascript that mirrors your server-side java. It will generate client-side proxies that you can call in your javascript. So instead of using jquerys $.ajax(...) command and specifying the url, data type, data, etc, you can just use RemoveObj.doSomeStuff(...) and it'll do the actual AJAX request for you, behind the scenes.
This is basically what ASP.NET does too when you declare a [WebMethod]. Its simply a shortcut and might save time with maintenance, e.g. if your urls change I suspect DWR will update its client-side code too.
My only issue with this is that it seems to pollute the namespace.
To actually answer your question it does nothing you can't do with normal javascript and servlets.

Categories

Resources