Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
Requesting page on button click with Spring, Thymeleaf and js

so I've done simple implementatnion on reload-less content loading. It uses AJAX to load content from another controller.

$(document.body).on('click', 'button#first', function() {
    $('#content').load("/first");
});

$(document.body).on('click', 'button#second',function() {
    $('#content').load("/second");
});

For now I have 3 controllers:

  • HomeController (localhost/)
  • FirstController (localhost/first)
  • SecondController (localhost/second)
@GetMapping("/first")
public String getFirst() {
    return "includes/first:: content";
}

@GetMapping("/second")
public String getSecond() {
    return "includes/second :: content";
}

And that works fine, but of course I can also just enter /first or /second and get unproper content as they're fragments. So my question is there any way to prevent people from just entering /first in their browser or handle loading content server-side instead of ajax?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!