In my opinion, developing a Web based application in JSP (Java) is more or less like killing a housefly with a bazooka. Of course you will hit your target, no one is denying that, but you will also have collateral damage along with it. This damage ranges from Cost of hardware, hosting, servers and development. Not to mention the time taken to develop, edit or modify the application.
But, that’s just me, I’ll let you to decide and let me know after going through these factors.
|
SNO |
Function / Feature |
JSP |
PHP |
|
1. |
Programming Approach |
1. Completely Object Oriented
Advantage: · Clean code
Disadvantage: · Way too descriptive |
1. Mainly a Scripting Language 2. It can also be used in OOPS from PHP 5 and above. Advantage: · Functional and quick coding, you can use OOP practices at your convenience Disadvantage: · May get clumsy |
|
2. |
String and data manipulation |
Rich library, too much descriptive and object oriented code |
Rich functionality. Functional and easy coding. Has inbuilt support to use third party libraries from other programming languages like Java, C and Dot.net |
|
3. |
Web Oriented features
|
Advantage: · Almost everything is built in or supported by libraries. Disadvantage: · Complicated and way too much of code. |
Advantages: · Inbuilt functionality and easy to use functions, written for the specific tasks · Reduces the lines of code and time taken to write an application. |
|
4. |
Database Access features |
Standard JDBC structure/ Use EJB/ Struts framework built over JDBC. Descriptive and too much overhead or boiler plate code involved. Uses the same API for all databases using JDBC drivers |
Dedicated inbuilt libraries for most of the commonly used databases. Very tight integration with Oracle, MySQL and PostGRE SQL. Very minimal boiler plate code required. The libraries and results are straight forward, robust and easy to use. |
|
5. |
XML/XSL/XPATH |
Use standard SAX/DOM parsers. Too much boiler plate code involved. Well defined APIs and stable implementations are available for XSL and XPATH |
SAX and DOM parsers available are easy to use and to the point. Another library, Simple XML provides very easy OO approach to handling XML data. XSL and XPATH functionality is also built in. |
|
6. |
Extensibility |
Java Classes and Libraries. Run’s in sandbox and hard JNI approach needed to integrate with server programs. |
PHP/C/Any thing executable by the underlying OS platform. Can very easily interact with programs on the server. Very good support for native code. |
|
7. |
Dynamic Graphics/PDF and bells and whistles |
Almost everything has a readymade library |
Supported internally or though libraries. |
|
8. |
Web Services/SOAP |
Addon Libraries like Axis, JAX-WS, etc. |
In Built |
|
9. |
Portals |
Spec JSR-168 and 286 |
Many different Portal frameworks |
|
10. |
Learning curve |
It helps if you have an decent understanding of JAVA and its architecture. |
If you know C/C++, then you are halfway through to learn PHP. |
|
11. |
Support |
It has support and backing of Industry giants like Sun and IBM. |
It enjoys the backing of Oracle, Sun, IBM, Microsoft and Zend. |
|
12. |
Hardware cost and requirement. |
Well this is one factor which makes PHP a favourite. The cost of procuring a server is exponentially higher than that of getting PHP server up and running. |
Cost of hosting a small and medium scale PHP application start from as low as $9 per month. For a decent enterprise level application server with an enterprise PHP framework, the cost would come out to be around $50 per month. |
Sample Codes for comparison
1. Hello World
|
JSP |
PHP |
|
<html> <head> </head> <% out.println(” Hello World”); %> ! </body> |
<html> <head> </head> <?php echo ”Hello World”; ?> </body> |
2. Print Date as DD/MM/YYYY
|
JSP |
PHP |
|
<html> <head> </head> <% java.util.Calendar cal =java.util.Calendar.getInstance(); out.println( new SimpleDateFormat(“dd/MM/yyyy).format(cal.getTime()?) ); %> |
<html> <head> </head> <?php echo date(“d/m/Y”); ?> </body> |
3. Read / Write session variable
|
JSP |
PHP |
|
<html> <head> </head> <% //Get current session or create a new session HtppSession session = request.getSession(true);
//Add information to the session session.setAttribute(“name”, “Pramati”);
//Print the information out.println(session.getAttribute(“name”); %> </body> |
<html> <head> </head> <?php //Get current session or create a new session session_start();
//Add information to the session $_SESSION['name']= “Pramati”;
//Print the information echo $_SESSION['name']; ?> </body> |
4.
a. File Uploading - Form
|
JSP |
PHP |
|
<html> <head> </head> <form action=”ProcessFileUpload.jsp” method=”post” enctype=”multipart/form-data”>
File 1:<input type=”file” name=”file1″/> <br/> <input type=”submit” name=”Submit” value=”Upload File”/> </form> </body>
Please Note: No in-built support for file uploading in JSP. You have to rely on external libraries. This example uses Apache’s commons-upload lib.
|
<html> <head> </head> <form action=”ProcessFileUpload.php” method=”post” enctype=”multipart/form-data”>
File 1:<input type=”file” name=”file1″/> <br/> <input type=”submit” name=”Submit” value=”Upload File”/> </form> </body> |
4.
b. File Uploading – Backend Code
|
JSP |
PHP |
|
Code for ProcessFileUpload.jsp <% if(ServletFileUpload.isMultipartContent(request))? { FileItemFactory f = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(f); List items = upload.parseRequest(request); Iterator itemsIter = items.getIterator(); if(iter.hasNext())? { File uploadedFile = new File(item.getName()); item.write(uploadedFile); } } %>
Please Note: No in-built support for file uploading in JSP. You have to rely on external libraries. This example uses Apache’s commons-upload lib.
|
Code for ProcessFileUpload.php <?php if ($_FILES["file"]["error"] > 0)? { echo “Error: ” . $_FILES["file"]["error"]; } else { move_uploaded_file( $_FILES["file"]["tmp_name"], “upload/” . $_FILES["file"]["name"]); } ?> |
5. Connect to the Database (MySql)
|
JSP |
PHP |
|
<%@ page import=”java.sql.*” %> <% Connetion conn = null; java.sql.Connection conn= null; Statement st = null; ResultSet rs = null;
try { Class.forName(”com.mysql.jdbc.Driver”).newInstance(); Class.forName(”org.gjt.mm.mysql.Driver”).newInstance(); conn = DriverManager.getConnection( “jdbc:mysql://localhost/jsp?user=xxx&password=xxx”); st = conn.createStatement(); // connection made…. |
<?php $dbserver=”locations”; $username=”username”; mysql_connect($dbserver,$username,$password);
//connection made… ?> |

If you liked my post, feel free to subscribe to my rss feeds




































3 Comments so far (Add 1 more)