Results 1 to 9 of 9
  1. #1
    Blue2525989 is offline Senior Member
    Join Date
    Sep 2016
    Posts
    108
    Rep Power
    0

    Default spring baby steps

    Hello all, So I have been adventuring with Spring Boot to try and learn. So far I have a boot application that can add to or show all elements in a MySQL database. i either put localhost/sql/all to show them all or localhost/sql/add?ID=1&name=jason&brief=whatever&description=wha tever&rank=5 to add a new entry.

    What I want to do now is add web pages where I can have a form instead of typing it all in the address bar. So do I use jsp or html or how should I approach this? I use gradle to build not maven I dunno if that matters in terms of approach or not. Any good tutorials or links to ideas would be appreciated, thanks.

  2. #2
    Blue2525989 is offline Senior Member
    Join Date
    Sep 2016
    Posts
    108
    Rep Power
    0

    Default Re: spring baby steps

    also I am having a problem with this file. when I click submit it loads a page that says:

    Java Code:
    Whitelabel Error Page
    
    This application has no explicit mapping for /error, so you are seeing this as a fallback.
    Sun Feb 12 16:15:51 CST 2017
    There was an unexpected error (type=Method Not Allowed, status=405).
    Request method 'POST' not supported

    here is the code. If you need the related files to know whats wrong let me know ill post it.

    Java Code:
    package jasonWebpage;
    
    import javax.validation.Valid;
    
    import org.springframework.stereotype.*;
    import org.springframework.validation.*;
    import org.springframework.web.bind.annotation.*;
    import org.springframework.web.servlet.config.annotation.*;
    
    @Controller
    public class PersonController extends WebMvcConfigurerAdapter{
    
        @Override
        public void addViewControllers(ViewControllerRegistry registry) {
            registry.addViewController("/results").setViewName("results");
        }
    
        @GetMapping("/form")
        public String showForm(jasonWebpage.PersonForm personForm) {
            return "form";
        }
    
        @PostMapping("/form")
        public String checkPersonInfo(@Valid jasonWebpage.PersonForm personForm, BindingResult bindingResult) {
    
            if (bindingResult.hasErrors()) {
                return "form";
            }
            String go = "/result.html";
            return "redirect:/results";
        }
    }

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: spring baby steps

    These days the site would be HTML/Javascript, rather than JSP. Or at least mostly that.
    So the Javascript on a page makes requests for whatever data the page is expected to show.
    There are frameworks for doing this. AngularJS is the current workhorse, but you might want to look at newer ones, like React.

    So essentially your site consists of Javascript that makes RESTful calls to your services and uses the results to construct the page.

    As for your second part. is there a stack trace on the server?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    Blue2525989 is offline Senior Member
    Join Date
    Sep 2016
    Posts
    108
    Rep Power
    0

    Default Re: spring baby steps

    ah thanks for the explaination, that makes sense. There are some guides on the spring web site for AngularJS. I will check those out.

    and this is what the error says

    Java Code:
    Whitelabel Error Page
    
    This application has no explicit mapping for /error, so you are seeing this as a fallback.
    Mon Feb 13 08:26:06 CST 2017
    There was an unexpected error (type=Method Not Allowed, status=405).
    Request method 'POST' not supported
    All I am trying to do is load a simple html file I have saved in a folder named templates. I followed the instructions on the spring web site on how to set everything up, so all my folders are in correct spots. However I wonder that I keep a lot of the html files in a folder called static which is at the same level as templates.

    I combined like 3 examples into one so in two of the examples it told me to have a index in static folder. So I did that and built upon that making some pages I can click back and forth between. Then one of the examples had all the html files in the templates folder so I put those ones there and these are the ones that I have problems getting.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: spring baby steps

    And there's nothing in the server logs?

    What's the URL you are hitting?

    Stick some debugging in the POST method to see if it even gets there (doesn't look like it to me).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Blue2525989 is offline Senior Member
    Join Date
    Sep 2016
    Posts
    108
    Rep Power
    0

    Default Re: spring baby steps

    WARN 7772 --- [nio-8080-exec-8] o.s.web.servlet.PageNotFound : Request method 'POST' not supported

    Not finding the page. I am going to look into more examples and see if i can't figure it out.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: spring baby steps

    I'd still put some debugging in there.
    Java Code:
    log.debug("Request to checkPersonInfo");
    Those, right at the start of the method, are immensely useful for simply seeing whether it has reached your code or not.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    Blue2525989 is offline Senior Member
    Join Date
    Sep 2016
    Posts
    108
    Rep Power
    0

    Default Re: spring baby steps

    okay I shall try that. I haven't messed with the log much yet.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: spring baby steps

    Now is the time to learn.
    :)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Predicting the gender of a baby HELP PLEASE
    By finn_the_human in forum New To Java
    Replies: 4
    Last Post: 09-10-2014, 10:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •