PHP to JSP convert

My PHP Code:


<?php
$db = new SQL(...);

$result = $db->query("SELECT * FROM abc");
$data = array();
while($row = $db->fetchArray($result))
{
    $row['title'] = '<b>'.$row['title'].'</b>';
    $data[] = $row;
}
$template['row_data'] = $data;

?>


<!-- Template -->
<ul>
    <?php foreach($template['row_data'] as $r) : ?>
    <li><?php echo $r['title']; ?></li>
    <?php endforeach; ?>
</ul>

Thanks very much.

You should post this in the Looking To Hire forum as I don’t think people want to do your work for you for free.

Ohhhhhhhhhhhhhh. Migrating from PHP to JSP. 20 lines of code. How much?
Im a PHP programmer, now Im jump over to JSP.

You can go to a “jsp and jdbc tutorials” site and try to convert it, we know nothing about database connections etc…
Anyway ti is rather easy and will be easier for you since you know what you want.
You may use jstl
Dimis

is there any tools to convert ???

Anyway, I thing to create a jsp script that connects to a database, do a query and print the result is very basic and you will find sample code at almost java books (or at online jsp/jdbc tutorials).
If you now the basics of Java (jsp etc even better) maybe you will understand to use JSTL tags to do that because it use less code and it is simple (maybe if you understant the tutorials you may not need to know java but it is a problem anyway to write with a language that you know nothing about-you may try to learn that since you will write with that).
jstl
jsp tutorial

brandlover.vn, just curious why you would convert from php to jsp?
Let say you have 10 php files that got converted to 10 jsp files… what does that buy you?

Plus, putting business logic code in JSP (like accessing to db) is considered BAD practice in Java world and no company will hire such Java developer!

With that said and assuming you are coming from PHP world, I can see that you would think “I can convert this into php to jsp easily”. Well… I can tell you that debugging in JSP is clearly hearder! in PHP, it gives specific line w/ pretty good error description. In JSP (at least for Tomcat), you have an error… most of the time you have “NullPointerException” which points to nowhere and later it turns out you missed “;” in line 344. In PHP (I did lil), you don’t have to import libraries, but in JSP…it gets a bit complicated along w/ JSTL or you may just embed Java Code. Now, I ask again… why would you convert PHP to JSP?

Also, Java Web Application that is 100% JSP is considered “pure crap”. Well unless it has less than say 3-5 jsp then fine… but more than that it’s crap. Not saying, it won’t be working. In fact, it could be 100% bug free but maintaining the code will be a nightmare.

Anyways, why would you convert from PHP to JSP?

No and I’m glad there aren’t.

With that said and assuming you are coming from PHP world, I can see that you would think “I can convert this into php to jsp easily”. Well… I can tell you that debugging in JSP is clearly hearder! in PHP, it gives specific line w/ pretty good error description. In JSP (at least for Tomcat), you have an error… most of the time you have “NullPointerException” which points to nowhere and later it turns out you missed “;” in line 344. In PHP (I did lil), you don’t have to import libraries, but in JSP…it gets a bit complicated along w/ JSTL or you may just embed Java Code. Now, I ask again… why would you convert PHP to JSP?

This is quite true, and the reason being you’re not really supposed to put code like that into your JSP.

Also, Java Web Application that is 100% JSP is considered “pure crap”
Very true. PHP is a language which can handle everything for your site, while JSP is just a part of J2EE. You won’t hear a developer say I did a JSP site. They’ll say I did a J2EE site, or a Java site, or a Java web site. JSP only handles the view. You would never connect to a database in a JSP page. Only in tutorials, but never in a production environment. It just doesn’t happen. Not to say it can’t be done, but no one does it.

is there any tools to convert ???
well that just makes me laugh :slight_smile: no.

By not sounding rude to you, why does it make you laugh? i mean, the whole idea of J2EE/jsp is to seperate the view logic from the business logic. You might be a php programmer(i guess) coz i see you’r loyalaties towards php more. I agree the point that you cant make a website in jsp, but there are websites made in java/jsp using many of the frameworks that is available for example struts(to start with). It basically depends upon the requirements of the client so to speek. I personally feel that php is more of code clutter kinda phenomena coz you write all the logic in it. Just my opinion, its a subjective thought though(may be because im a j2ee developer :)).
Just my thoughts, not to sound rude mate :slight_smile:
regards,
ajos777

sunbck you said:

is there any tools to convert ???

My answer:

Yes!!! Read a book.

OO programming has come a long way in PHP though so you can seperate business logic…at least I think so :wink: That’s my three cents :wink:

I thing php 5 has many OOP improvements, so you may write code that implements MVC as with JAVA these days.
As in J2ee, there are some framerworks that can help you at your work…

To me, w/o using MVC framework to build an webapp is like eating a hamburger w/o a meat.

My idea is similar but not the same.

If you download resin for java and querticus, you can run your php as java :slight_smile:

I have already use it!
I thing it is not 100% compatiple, for example I tried to set up studs (as struts) a framework for php and it did not work, maybe resin wait java classes at lib/classes and not php classes, maybe i did not cofigure that properly.
I found and something else but I do not remember, maybe also it were a configuration error.
I thing quercus run and at other java servers.