0

I have a very simple project Parking Space Booking System made in PHP. I have to change it to Java. I've passed HTML5 form values (number of space, start date, end date, name, phone) according to this tutorial: https://netbeans.org/kb/docs/web/quickstart-webapps.html

I printed them in response.js file<jsp: getProperty name="mybean" property="x" /> where x is name/number/start/end/phone -> for each separate line and those values are properly send from HTML5 and displayed. My question is now if I want to make logic operations should I use tag <% %> and put ther Java code like in PHP and <? ?> tag? Will I be able use then JDBC within <% %> and connect / send data / user queries to MySQL server?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Luke_Nuke
  • 461
  • 2
  • 6
  • 23
  • 1
    The fact that you can does not mean it's a good idea. You should call a class that takes care of connecting to the DB. – Federico klez Culloca Jun 20 '18 at 10:35
  • copying to JSP project PHP philosophy is one of the worst anitipatern. Why not make simply in PHP? – Jacek Cz Jun 20 '18 at 10:41
  • 3
    [How to avoid Java code in JSP files?](https://stackoverflow.com/q/3177733) – Pshemo Jun 20 '18 at 10:41
  • bad designed Java project has only downsides comparing to PHP – Jacek Cz Jun 20 '18 at 10:57
  • Idioms in one language are not idioms in other. – Jacek Cz Jun 20 '18 at 10:57
  • Ok, thank you I just started Java I didn't know this is so bad and anti-pattern. So I'll avoid it. Any ideas how can I get a connection to DB and use the class to handle operations on data? Any tutorials? I have to use Java and have to use Tomcat. I found something on netbeans tutorials but it requires GlassFishTank. Please can you tell me is it possible to do it porperly (according to patterns) use JSP and JDBC. – Luke_Nuke Jun 20 '18 at 11:00
  • I have one more question. Please tell me if I'm using JDBC how do I shall pass HTML5 form data to Java? Using JSP or there is another way if using JDBC? – Luke_Nuke Jun 20 '18 at 11:11
  • In my opinion raw JSP in 2018 is one big antipattern. I can accept use in presentation layer (View) with architectural framework JSF, Struts, Spring. – Jacek Cz Jun 20 '18 at 11:11
  • So this: https://www.ntu.edu.sg/home/ehchua/programming/java/JSPByExample.html is wrong now? – Luke_Nuke Jun 20 '18 at 11:39

1 Answers1

0

Have you tried it? In theory you should be able to. Also, does it have to be plain JSP with Scriptlet? You could use Servlets, which are pretty simple to use (especially with @WebServlet annotation, here you can find a few examples). And then separate your logic into layers: View, Controller, Model or any other layer separation that you find it useful. Avoid <% %> and use html form actions.

paulo.bing
  • 82
  • 10
  • I want to use just Tomcat server. My problem is I use JSP to send html5 form data to Java but I can't handle them. I mean some people wrote I comment above to "You should call a class that takes care of connecting to the DB" I understand but I don't really know how and couldn't find clear guidence from this point: https://netbeans.org/kb/docs/web/quickstart-webapps.html Is tis wrong If I want connect and us mySQL server. I shall use diffrent way? – Luke_Nuke Jun 20 '18 at 11:08
  • 1
    The link you are providing seems to be ok, but it does not interact with database. If you want to learn how to connect to database, this is and old but working example of jsp + servlet + mysql (tomcat is fine, don't worry): https://danielniko.wordpress.com/2012/04/17/simple-crud-using-jsp-servlet-and-mysql/ Or a more modern approach using Spring MVC, where you don't have to code any query nor bind manually database rows and columns to java fields: https://www.journaldev.com/3531/spring-mvc-hibernate-mysql-integration-crud-example-tutorial Let me know if any of them seem ok to you. – paulo.bing Jun 20 '18 at 13:16