What Is the Main-Stream Java Alternative to ASP.NET/Php

What is the main-stream Java alternative to ASP.NET / PHP

The Java equivalent of PHP and "Classic" ASP would be JSP (JavaServer Pages) with scriptlets (embedded raw Java code). Scriptlets are considered poor practice in Java web development world. Taglibs and EL (Expression Language) should be preferred above scriptlets. The Java equivalent of ASP.NET (MVC) would be a Java MVC framework. There are a lot of Java-based MVC frameworks out, mostly providing a Servlet/Filter-based controller and taglibs to interact with the model (usually a Javabean) and the view (usually a JSP page, but XHTML is also possible).

To start, the Java EE API provides JSF (JavaServer Faces) for this, which in turn comes along with XHTML based templated view technology known as Facelets. Facelets is seen as a replacement of the good old JSP. Further, there are a lot of open source Java MVC frameworks which are built on top of the JSP/Servlet API and which are intended as an alternative/competition to JSF. You can find little information of all of them here, the popular ones being Spring MVC, Struts2 and Stripes.

As to which one to choose, I suggest having a look at this answer which I strongly agree.

JSP equivalent of ASP.NET MVC's partial views?

There isn't. JSP is not a fullworthy equivalent of ASP.NET MVC. It's more an equivalent to classic ASP. The Java equivalent of ASP.NET MVC is JSF 2.0 on Facelets.

However, your requirement sounds more like as if you need a simple include page. In JSP you can use the <jsp:include> for this. But it offers nothing more with regard to templating (Facelets is superior in this) and also nothing with regard to component based MVC (there you have JSF for).

Basic example:

main.jsp

<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
</head>
<body>
<h1>Parent page</h1>
<jsp:include page="include.jsp" />
</body>
</html>

include.jsp

<h2>Include page</h2>

Generated HTML result:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
</head>
<body>
<h1>Parent page</h1>
<h2>Include page</h2>
</body>
</html>

See also:

  • What is the Java alternative to ASP.NET/PHP?
  • Analogues of Java and .NET technologies/frameworks
  • What is the difference between JSF, JSP and Servlet?

Java EE Website Planning Questions

  • Is there a recommended technology for the presentation layer? Is JSP considered a good approach, or is there anything cleaner/newer/more widespread?

JSP has been replaced by Facelets. It provides an excellent templating fit for JSF, Sun's MVC framework (the Java counterpart of ASP.NET MVC). If you don't go for JSF, then Facelets has not much benefit for you and you could just continue with legacy JSP, probably with a 3rd party templating framework on top like Freemarker or Velocity and/or a 3rd party MVC framework like Spring MVC, Struts2 or Stripes. I however strongly recommend to just go ahead with Facelets+JSF on Java EE 6.

  • Is Hibernate still widely used for persistence? Is it obsolete? Is there anything better out there? (I've worked with NHibernate some, so I wouldn't be starting from scratch.)

It's certainly not obsolete. It has just expanded its powers with a JPA implementation. Even more, the guy behind (N)Hibernate, Gavin King, has worked on the Java EE's JPA specification himself.

  • Is cheap Java EE web hosting available?

Only eatj.com, javaservlethosting.com and Google Appengine comes to mind.

  • What should I know being a .NET web developer moving to the Java world?

Maybe any of those answers will be helpful:

  • What is the difference between JSF, Servlet and JSP?
  • java web development, what skills do I need?
  • What is the main-stream Java alternative to ASP.NET / PHP
  • Analogues of Java and .NET technologies/frameworks

Technical differences between ASP.NET and Java Servlets / JSP

JSP pages are translated into Java source code, then compiled into class files (containing Java Byte Code) for future execution. After that, they're actually JIT (Just In Time) compiled by the JVM when they are needed for execution (so they're pretty fast).

It's my guess that there's a similar process for .NET applications, in that they are compiled into .NET assemblies. This is sort of like Java's class files, except they are IL (Intermediate Language) to run on the CLR. At run time, IL is also translated into native machine instructions for execution.

The actual build / runtime mechanisms (from a high level) are probably surprisingly similar.

EDIT

Here are some details regarding ASP.NET : http://msdn.microsoft.com/en-us/library/ms366723.aspx

Also, with Java based web applications, containers which run them can be configured to pre-compile JSPs when the application is deployed. Then, the JVM loads the class files into memory, and handles JIT compilation / caching from that point forward.

Servlets, JSP, Java?

Servlets are HTTP listeners that run in a servlet/JSP application engine like Tomcat, Jetty, etc.

JSPs are templates that are compiled into servlets. They allow you to write HTML-generating servlets in a tag-like template notation in such a way that dynamic behavior is possible.

Dynamic web page built in jsp to any advance java framework

Try Java Server Faces. This is more convenient to migrate JSP developer.Check these link

  • JavaServer Faces Technology
  • JavaServer Faces Community

JSF has many resources and easily to use together with ajax.

Switching from ASP.NET MVC to Java

ile,

unfortunately, i think you'll find that there's a huge amount of collaterol in JSF with your collegues. in my opinion, you'd be better to start off with JSF as you'll have a lot of knowledge that you can feed off of initially there. then you could investigate the alternatives and try to get some peer buy-in to some of your initiatives.

see: https://gmvc.dev.java.net/

so for now, suck and see i guess.

[edit] - spring seems popular as well http://en.wikipedia.org/wiki/Spring_Framework_%28Java%29



Related Topics



Leave a reply



Submit