Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8563547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:59:04+00:00 2026-06-11T16:59:04+00:00

I am trying to build a RESTFUL Web Service however I am getting an

  • 0

I am trying to build a RESTFUL Web Service however I am getting an error under is my code:

jsp

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>

    <style>
        <%@ include file="../css/forms.css" %>
    </style>
    <script type="text/javascript">
        <%@ include file="../js/off_reg.js"%>


        $(document).ready(function(){

            $('#userName').blur(function(evt){


                CheckAvailability();                    
            });
        });         

        function CheckAvailability(){

            $.ajax( {
                  type:'GET', //Could be 'get' depending on your needs
                  url:'validateUserName.htm',
                  data:{userName:$('#userName').val()},
                  dataType: 'json',
                  success:function(data) {
                    alert(data);
                  }
                });

    }



    </script>

DAO

public boolean OfficerExist(String userName){


    try{

        logger.debug("About to check if officers existing");

        String sql = "SELECT userName FROM crimetrack.tblofficers WHERE userName = ?";

        logger.info("at this point 1");

        //String dbUserName = (String)results.get("userName");

        String dbUserName = (String)getJdbcTemplate().queryForObject(sql, new Object[]{userName},String.class);


        logger.info("after JdbcTemplate");

        if (dbUserName.equals(userName)) {

            logger.info("User Name Exists");
            return true;

        }else{
            logger.info("User Name Does NOT Exists");
            return false;
        }


    }catch(Exception e){

        logger.info(e.getMessage());
        return false;
    }
}

FireBug Console Error:

GET http://localhost:8084/crimeTrack/validateUserName.htm?userName=hello

500 Internal Server Error
    70ms    
jquery.min.js (line 2)

"NetworkError: 500 Internal Server Error - http://localhost:8084/crimeTrack            /validateUserName.htm?userName=hello"

TomCat Error Log:

    com.crimetrack.web.OfficerRegistrationController.validateUserName(java.lang.String,com.crimetrack.business.Officers,org.springframework.validation.BindingResult,org.springframework.ui.ModelMap) throws java.lang.Exception
306270 [http-8084-1] DEBUG com.crimetrack.web.OfficerRegistrationController  - Inside Controller validateUserName
306270 [http-8084-1] DEBUG com.crimetrack.web.OfficerRegistrationController  - The user name that came in is hello
306270 [http-8084-1] INFO  com.crimetrack.service.ValidateUserNameManager  - Inside Do UserNameExist
306270 [http-8084-1] DEBUG com.crimetrack.jdbc.JdbcOfficersDAO  - About to check if officers existing
306270 [http-8084-1] INFO  com.crimetrack.jdbc.JdbcOfficersDAO  - User Name Found 1
306270 [http-8084-1] INFO  com.crimetrack.jdbc.JdbcOfficersDAO  - User Name Found 2
306270 [http-8084-1] DEBUG org.springframework.jdbc.core.JdbcTemplate  - Executing prepared SQL query
306270 [http-8084-1] DEBUG org.springframework.jdbc.core.JdbcTemplate  - Executing prepared SQL statement [SELECT userName FROM crimetrack.tblofficers WHERE userName = ?]
306270 [http-8084-1] DEBUG org.springframework.jdbc.datasource.DataSourceUtils  - Fetching JDBC Connection from DataSource
306285 [http-8084-1] DEBUG org.springframework.jdbc.core.StatementCreatorUtils  - Setting SQL statement parameter value: column index 1, parameter value [hello], value class [java.lang.String], SQL type unknown
306289 [http-8084-1] DEBUG org.springframework.jdbc.datasource.DataSourceUtils  - Returning JDBC Connection to DataSource
306289 [http-8084-1] INFO  com.crimetrack.jdbc.JdbcOfficersDAO  - Incorrect result size: expected 1, actual 0
306289 [http-8084-1] DEBUG org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver  - Resolving exception from handler [com.crimetrack.web.OfficerRegistrationController@a32cdd]: java.lang.IllegalArgumentException: Invalid handler method return value: false
306289 [http-8084-1] DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver  - Resolving exception from handler [com.crimetrack.web.OfficerRegistrationController@a32cdd]: java.lang.IllegalArgumentException: Invalid handler method return value: false
306289 [http-8084-1] DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver  - Resolving exception from handler [com.crimetrack.web.OfficerRegistrationController@a32cdd]: java.lang.IllegalArgumentException: Invalid handler method return value: false
306290 [http-8084-1] DEBUG org.springframework.web.servlet.DispatcherServlet  - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@1cbab62
306290 [http-8084-1] DEBUG org.springframework.web.servlet.DispatcherServlet  - Could not complete request
java.lang.IllegalArgumentException: Invalid handler method return value: false
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.getModelAndView(AnnotationMethodHandlerAdapter.java:971)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:438)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)
306290 [http-8084-1] DEBUG org.springframework.web.context.support.XmlWebApplicationContext  - Publishing event in WebApplicationContext for namespace 'crimetrack-servlet': ServletRequestHandledEvent: url=[/crimeTrack/validateUserName.htm]; client=[127.0.0.1]; method=[GET]; servlet=[crimetrack]; session=[null]; user=[null]; time=[28ms]; status=[failed: java.lang.IllegalArgumentException: Invalid handler method return value: false]
306290 [http-8084-1] DEBUG org.springframework.web.context.support.XmlWebApplicationContext  - Publishing event in Root WebApplicationContext: ServletRequestHandledEvent: url=[/crimeTrack/validateUserName.htm]; client=[127.0.0.1]; method=[GET]; servlet=[crimetrack]; session=[null]; user=[null]; time=[28ms]; status=[failed: java.lang.IllegalArgumentException: Invalid handler method return value: false]

OfficerRegistrationController

package com.crimetrack.web;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.apache.log4j.Logger;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.crimetrack.business.Login;
import com.crimetrack.business.Officers;
import com.crimetrack.service.DivisionManager;
import com.crimetrack.service.GenderManager;
import com.crimetrack.service.OfficerRegistrationValidation;
import com.crimetrack.service.PositionManager;
import com.crimetrack.service.ValidateUserNameManager;

@Controller
public class OfficerRegistrationController {

    private final Logger logger = Logger.getLogger(getClass());
    private DivisionManager divisionManager;
    private PositionManager positionManager;
    private GenderManager genderManager;
    private Officers officer = new Officers();

    private ValidateUserNameManager validateUserNameManager;

    Map<String, Object> myDivision = new HashMap<String, Object>();
    Map<String, Object> myPosition = new HashMap<String, Object>();
    Map<String, Object> myGender = new HashMap<String, Object>();



    OfficerRegistrationValidation validateData = new OfficerRegistrationValidation();

    @InitBinder("officers")
    protected void initBinder(WebDataBinder binder){
        //removes white spaces 
        binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));

        //formats date 
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

        //By passing true this will convert empty strings to null
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
        dateFormat.setLenient(false);

        binder.setValidator(new OfficerRegistrationValidation());

    }


     @RequestMapping(value="officer_registration.htm", method = RequestMethod.GET)
        public ModelAndView loadPage(HttpServletRequest request,
                HttpServletResponse response,@ModelAttribute Officers officer, BindingResult result, ModelMap m, Model model) throws Exception {     


         try{            

             logger.debug("In Http method for OfficerRegistrationController");


                myDivision.put("divisionList", this.divisionManager.getDivisions());


                myPosition.put("positionList", this.positionManager.getPositionList());


                myGender.put("genderList", this.genderManager.getGenderList());

                model.addAttribute("division", myDivision);
                model.addAttribute("position", myPosition);
                model.addAttribute("gender", myGender);

             return new ModelAndView("officer_registration");            


         }catch(Exception e){

            request.setAttribute("error",e.getMessage());
            return new ModelAndView("error_page");           
         }       
     }

     @RequestMapping(value="officer_registration.htm", method=RequestMethod.POST)
     public ModelAndView handleRequest(@Valid @ModelAttribute Officers officer, BindingResult result, ModelMap m, Model model)throws Exception{

         if(result.hasErrors()){

             model.addAttribute("division", myDivision);
             model.addAttribute("position", myPosition);
             model.addAttribute("gender", myGender);
             return new ModelAndView("officer_registration");

        }else{

            return null;
        }   

     }

     @RequestMapping(value="validateUserName.htm", method=RequestMethod.GET)
     public boolean validateUserName(@RequestParam String userName, @ModelAttribute Officers officer, BindingResult result, ModelMap m)throws Exception{


         try{

             logger.debug("Inside Controller validateUserName");
             logger.debug("The user name that came in is " + userName);

            if (validateUserNameManager.DoesUserNameExist(userName)== true){

                 return true;
             }

                 return false; 

            // return true;


         }catch(Exception e){

             logger.debug("Error in validateUserName Controller " + e.getMessage());
             return false;

         }


     }



     public void setDivisionManager(DivisionManager divisionManager){

         this.divisionManager = divisionManager;
     }

     public void setPositionManager(PositionManager positionManager){

         this.positionManager = positionManager;

     }

     public void setGenderManager(GenderManager genderManager){

         this.genderManager = genderManager;
     }



    /**
     * @return the validateUserNameManager
     */
    public ValidateUserNameManager getValidateUserNameManager() {
        return validateUserNameManager;
    }

    /**
     * @param validateUserNameManager the validateUserNameManager to set
     */
    public void setValidateUserNameManager(
            ValidateUserNameManager validateUserNameManager) {
        this.validateUserNameManager = validateUserNameManager;
    }




    /**
     * @return the officer
     */
    public Officers getOfficer() {
        return officer;
    }



    /**
     * @param officer the officer to set
     */
    public void setOfficer(Officers officer) {
        this.officer = officer;
    }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:59:05+00:00Added an answer on June 11, 2026 at 4:59 pm

    Per Spring’s @RequestMapping documentation:

    Any other return type will be considered as single model attribute to be exposed to the view, using the attribute name specified through ModelAttribute at the method level (or the default attribute name based on the return type’s class name otherwise). The model will be implicitly enriched with command objects and the results of ModelAttribute annotated reference data accessor methods.

    Because this method has the ModelAttribute annotation on an Officers object, the return type is expected to be an Officers object.

    You probably want this method to return void, and write to the response object yourself. (To do that, you will need to add an HttpServletResponse parameter to your method.)

    Alternatively, you could return a JSON view. See spring: return JSON from controller as ModelAndVIew

    For example:

    public View validateUserName(@RequestParam String userName, ModelMap m) {
    
        // Do validation
    
        m.addAttribute("isValid", validationResult);
    
        return new MappingJacksonJsonView();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a restful web service for my website. I have
Trying to build Xuggler under Windows. Xuggler is core native code functions wrapped into
I'm having a frustrating time with Spring 3 MVC trying to build RESTful web
I'm trying to use the restlet.org library to build a RESTful web interface, and
I'm trying to build a RESTful internal web server at work using node.js, where
I have been trying to find a way to implement a RESTful web service
I'm trying to make a RESTful Web Service which implements all four CRUD operations.
I am new to PHP and was trying to build RestFull service in PHP
I'm trying to build a python library for interacting with our RESTful API, but
I need to build a web service, for a mobile game, to manage the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.