Is JSP a good choice in this scenario?


#1

Since I am planning to use Spring framework (Spring boot) and JSP goes well with Spring. Is it a good idea to use JSP for just HTML purpose? I am not going to use JSP for any other purpose other than displaying HTML.

The reasons I am considering using JSP are:

  1. It works well well with Spring
  2. I might have to user the server functionality if I plan do download flatfiles locally on the server somewhere.

Please let me know if I can clarify any questions. Thanks !


#2

. Is it a good idea to use JSP for just HTML purpose?

That’s what JSP does? It’s server rendering your html code, usually hydrated with data from your Spring backend.

Thymeleaf is also a good choice and works well with Spring.


#3

I’m not sure what or why you’re asking. There are any number of server-side languages capable of outputting web pages.

I guess the questions to ask are

  • are you familiar with the language and do you like working with it?
  • can you find a host that provides that language?
  • in the event you want more than web pages is that language a good choice for what you may want to do?

#4

The reason I was considering JSP is because it goes well with Spring. As such, I don’t want to use any JSP functionality except one thing. I might want to download a huge JSON response on the server using some flat file logic etc, and I guess I would need some server side language to achieve that. I haven’t used JSP before though but the only reason I was thinking about using it was because of Spring.

I know PHP but I don’t think I would be able to use it on front end with Spring?


#5

Maybe. But it would require a “bridge” and would probably be so much work it wouldn’t be worth the trouble. If you’re decided on using Spring then I think it would be more fruitful to go with Java even if you might have a bit of a learning curve to get over. Java is OOP, so if you know how to work with OOP the learning curve shouldn’t be that much of a problem for you.


#6

By using Java, are you referring to the User Interface part? If yes then could you name what user interface specific thing you are referring to?

I’m already using Java for RESTful web services ( Spring).

Thanks


#7

I might want to download a huge JSON response on the server using some flat file logic etc, and I guess I would need some server side language to achieve that.

I mean… no? You can do this in JS.


#8

Oh, is it? Could you point me to any documentation related to this please? Thanks!


#9

Fetch API, native alternative to AJAX


AJAX with Axios (most popular AJAX library)

AJAX with jQuery (only consider if you’re already using jQuery)
http://api.jquery.com/jquery.ajax/
https://api.jquery.com/jquery.getjson/
https://api.jquery.com/jquery.get/

Or build your own


#10

Thanks for the information. So, I am already using Ajax with jQuery. Basically, getting the response back from my Java webservice which is in the form of a JSON.

But here, I am wondering would it be possible to store the information in a flat file somewhere on the server so that the next time I won’t have to use the ajax call (which takes long time because of the webservice returning 20k records). Can this be done using Javascript? Please let me know if I am not understanding anything that you were trying to explain. Thanks !


#11

You can query a flat file in AJAX if that’s what you’re wondering. It sounds like you’re having issues with the parsing and rendering of that file. 20k records is a lot. Is there no way to paginate that so you can build it in pieces? There are other ways of solving this problem, I would imagine. A lot of apps don’t even use server side rendering anymore.


#12

I don’t know how much liberty you have to change things, but I would try something like

server-side - two API results

  • one to get only the “last information modification date”
  • another to get the information

client-side

  • check to see if information has been cached
  • check to see if information is current with server-side information

If the information has been cached client-side and the server-side information hasn’t changed, use the client-side information.

If the information does not exist client-side or if the server-side information has changed, request the server-side information.

IMHO choosing IndexedDB client-side would be a good choice, though I guess a file or something else could work too.


#13

Thanks again. Actually, I don’t even have a flat file right now. I just have a webservice which takes 4-5 mins (20k records) to return the results and figuring out other options.

In order to get the flat file, what should I do? I am wondering if I could generate a flat file with the JSON response that I am getting from web service or should I ask my database guy to generate a flat file. I believe fetching records from the file would come later on.


#14

I would call the file in multiple calls. There’s no way you’re using all 20k results at once.


#15

Ok. What would be an ideal approach to generate a file so that I could call it multiple times?


#16

I think you misunderstood. You probably don’t need to be calling so many results at once at all. There’s no reason to generate a large file. That is what the backend is for.


#17

I see. So, right now since my webservice is calling all 20k records ( because SQL is returning 20k records), when you say “That is what the backend is for” , did you mean that in this scenario, SQL should not be returning 20k records or should my web service be designed in some different manner? Thanks !


#18

The query on the database should be limiting results in some way based on whatever criteria is relevant. This should speed up whatever you’re getting back considerably. You really only need to be getting like 100-500 results back max, no matter what you’re querying. The absolute largest single query returned to a UI I’ve ever written was 6000, but I only did that because it was already fast enough (under 50ms for the query) and wasn’t hit often.

If it’s taking 5minutes, even for 20k records, then some other issues are coming in to play… especially if it’s just a single table. If it’s a single table, it might be an easy fix of adding some indexes. If it’s multiple tables, then the fix will be a little harder but should be able to be accomplished.

Whatever it is, generating a flat file because the query is taking too long is a bandaid, not a solution.


#19

I see. I might have to display 20k records to the user and have them download the results if they want to. When you say I should be getting “100-500” results max, are you referring something like pagination feature that I could use at the time of displaying the records on the table? But I guess in this scenario a user might have to do something multiple times to get 100-500 results back (For example, if I am displaying first 100 records, they would click next button on the table somewhere to get next set of 100 records and so on and so forth etc)

Do you think HTTP Caching mechanism could be an option?


#20

You could auto load these across multiple requests. Load the first 100, then the next after that’s done. This is more or less how infinite scrolling works. The user probably isn’t going to need to instantly interact with everything all at once.