Author Topic: I need to switch from PHP to Java.  (Read 1106 times)

STEVE

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 50
    • View Profile
I need to switch from PHP to Java.
« on: August 09, 2022, 09:15:18 pm »
Dear Paramvir,

Tomcat only supports java.  I can't use PHP because I can't configure the PDO to connect to PostgreSQL.

so I decided to transfer the PHP code to java code.

Although I don't know how to do that, I have to do change the PHP code to the java code.

Would you give me hints or related sample files like the attachments I uploaded?
i.e: how to send data and receive data between your grid and java code from the backend.


Best Regards,
Steve.

STEVE

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 50
    • View Profile
Re: I need to switch from PHP to Java.
« Reply #1 on: August 09, 2022, 09:33:23 pm »
I am sure the sample files as below.

Please check it out.

Thank you in advance.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: I need to switch from PHP to Java.
« Reply #2 on: August 10, 2022, 10:16:00 pm »
It's assumed that you are familiar with and have set up J2EE environment.

Java code is available for batch editing here: https://paramquery.com/pro/demos/editing_batch

You can modify it as per your requirements and kindly share issues faced if any.

Please note that java code is not available for Tree batch editing yet ( for which you had asked for PHP code earlier ).
« Last Edit: August 10, 2022, 10:21:55 pm by paramvir »

STEVE

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 50
    • View Profile
Re: I need to switch from PHP to Java.
« Reply #3 on: August 19, 2022, 06:17:12 pm »
Dear paramvir,

The java code didn't work.  Even I imported these components.

import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.jdbc.core.JdbcTemplate;

Error messages are below.

The type org.springframework.dao.support.DaoSupport cannot be resolved. It is indirectly referenced from required .class files


And, I need to know how to set up the pom.xml, web.xml, and servlet-context.xml on this problem.

Thank you.


STEVE

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 50
    • View Profile
Re: I need to switch from PHP to Java.
« Reply #4 on: August 19, 2022, 06:51:16 pm »
I changed it as below.

Code: [Select]
public class ProductsListController extends JdbcTemplate {

But Still, the problem exists.
Code: [Select]
List<Product> products = getJdbcTemplate().query(

I have to make a function to resolve this problem
Code: [Select]
private JdbcTemplate getJdbcTemplate() {
// TODO Auto-generated method stub
return null;
}


I had to learn java to implement pqGrid to the existing home page does not support PHP to show the excel data.

I want to keep my promise to them.

But I am afraid to disappoint them.

 

STEVE

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 50
    • View Profile
Re: I need to switch from PHP to Java.
« Reply #5 on: August 19, 2022, 08:57:29 pm »
I am trying to modify your sample java code.

I couldn't make it work.

I am attaching the files and two screenshots.

Its pattern is the MVC pattern. 

Please check my files.

if you could give me the executable files I will be happy enough.

Thank you.

STEVE

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 50
    • View Profile
Re: I need to switch from PHP to Java.
« Reply #6 on: August 21, 2022, 04:00:42 pm »
Hello?

I changed some codes. 
Please check the below files

My questions are so simple regarding these files.

I want to know how to set the value of the URL of Ajax from pqGrid.

It really is difficult to match each other.

from product.jsp

Code: [Select]
$.ajax({
                dataType: "json",
                type: "POST",
                async: true,
                beforeSend: function (jqXHR, settings) {
                    grid.showLoading();
                },
                url: "/aa/products/batch",                    //for ASP.NET, java
                data: { list: JSON.stringify(changes) },

to productController.java

Code: [Select]

@RequestMapping(value="/Products/clear", method=RequestMethod.GET)
    public @ResponseBody String clear(HttpServletRequest request ){
        HttpSession ses = fillInSession(request);
        //ses.setAttribute("Products", "");
        @SuppressWarnings("unchecked")
        List<Products> Products = (List<Products>)ses.getAttribute("Products");
        Products.clear();
        return "";
    }


Code: [Select]
@RequestMapping(value="/Products/batch", method=RequestMethod.POST)
    public @ResponseBody String batch(@RequestParam String list, HttpServletRequest request ){
        HttpSession ses = fillInSession(request);

        Map<String, List<Products>> dlist = deserializeMap(list);

        ArrayList<Products> updateList = (ArrayList<Products>)dlist.get("updateList");
        ArrayList<Products> addList = (ArrayList<Products>)dlist.get("addList");
        ArrayList<Products> deleteList = (ArrayList<Products>)dlist.get("deleteList");

        this.updateList(updateList, ses);
        this.addList(addList, ses);
        this.deleteList(deleteList, ses);

        return serializeMap(dlist);
    }

Code: [Select]
@RequestMapping(value="/Products/get",method=RequestMethod.GET)
    public @ResponseBody String Products(ModelMap model, HttpServletRequest request ){

        HttpSession ses = fillInSession(request);

        @SuppressWarnings("unchecked")
        List<Products> products = (List<Products>)ses.getAttribute("Products");

        String serializedProducts = serialize(products);

        String responseStr = "{\"data\":" + serializedProducts + "}";
        return responseStr;
    }

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: I need to switch from PHP to Java.
« Reply #7 on: August 22, 2022, 10:41:23 am »
url to get the products would be "/Products/get"

and url to post the changes would be "/Products/batch"

If records are not displayed in grid, I suggest you use debugging and set some breakpoints in your java code to find the issue.

STEVE

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 50
    • View Profile
Re: I need to switch from PHP to Java.
« Reply #8 on: August 23, 2022, 07:50:56 am »
I have trouble with a JSP file.

The CSS and JS files were not included

Code: [Select]

    <link rel="stylesheet" href="../css/jquery-ui.css" />
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/query-ui.min.js"></script> 


I put the json_exam.jsp file in the views folder beside the grid folder.
It works fine.

Quote
http://localhost:9080/aa/json_exam.jsp
-->
//localhost:9080/grid/ajax/jquery-ui.min.js

It is from the tomcat initiated with the eclipse tool.
It doesn't work due to an incorrect URL
Quote
http://localhost:8081/pgConn/json
--> it call json_exam.jsp file
--> this file refers to the js file below
http://localhost:8081/pgConn/js/jquery.min.js
--> 404 Error

Would you tell me how set the correct URL with some configuration in eclipse?

Please help me~

Many thanks for considering my request.

STEVE

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 50
    • View Profile
Re: I need to switch from PHP to Java.
« Reply #9 on: August 24, 2022, 02:30:17 am »

Hello?

I put the sample code of the product example in the webapp folder which is working on the tomcat.

I got an error message like this when I click the new button on the product sample code.


Code: [Select]

jquery.min.js:5

GET http://localhost:8081/product/get?pq_datatype=JSON&_=1661285986779 404


I want to know the reason why "pgConn" is disappeared.

Quote

http://localhost:8081/pgConn/product


And Why it doesn't work?


STEVE

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 50
    • View Profile
Re: I need to switch from PHP to Java.
« Reply #10 on: August 24, 2022, 03:56:51 am »
I forgot something important.

I got the error message from the eclipse console.

it was that "pgConn/product/gets" can not be resolved ..."

You gave me some advice to use the URL, "/product/gets"

I want to know the mechanism of the using URL between the Controller and JSP.

Thank you in advance.

STEVE

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 50
    • View Profile
Re: I need to switch from PHP to Java.
« Reply #11 on: August 24, 2022, 03:59:16 am »
Please help me~~~

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: I need to switch from PHP to Java.
« Reply #12 on: August 24, 2022, 10:47:34 am »
grid is not able to display any records, dataModel.url option should be set to "/Products/get" because of this requestMapping

@RequestMapping(value="/Products/get",method=RequestMethod.GET)