Java spring boot webservices 和 html

标签 java html spring

我在java Restful services中创建了一个Post方法。当前端用户第一次单击按钮时,将会出现一个错误页面,显示下面给出的错误消息,而我只是第一次收到此错误。当用户第二次单击它时,它工作正常。

白标错误页面

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Fri Jan 27 03:51:51 EST 2017 There was an unexpected error (type=Method Not Allowed, status=405). Request method 'GET' not supported

这是我的 Controller 文件:-

@RequestMapping(value="/classify",method = RequestMethod.POST)
public @ResponseBody    
List<List<HashMap<Object,Object>>> doClassify1( HttpServletRequest request,HttpServletResponse resp)  {

    try
    {
        System.out.println("Start of Classify");
        prop = new Properties() ;
        input = StwTagController.class.getClassLoader().getResourceAsStream("application.properties");
        prop.load(input) ;

        String rdurl  = prop.getProperty("plmclassify") ;
        String appId = request.getParameter("appId");

        String appType = request.getParameter("appType");
        String[] objectData =  request.getParameterValues("objectData");        
        parentId = request.getParameter("parentObjectId");
        String userId = request.getHeader("sm_ssoid");
        obj = stwTagService.doClassify(appId,appType,objectData,parentId,userId );      

        resp.sendRedirect(rdurl+parentId);
        } catch (IOException e) {

            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    return obj;
    }

最佳答案

正如您从错误消息中看到的:

Request method 'GET' not supported

您的 html 使用 HTTP GET 方法而不是请求映射所需的 POST 方法连接到您的 Web 服务:

 @RequestMapping(value="/classify",method = RequestMethod.POST)

关于Java spring boot webservices 和 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41890141/

相关文章:

spring - 服务器返回 HTTP 响应代码 : 400 using Spring-Security AuthenticationProvider

java - 在 Spring Framework JavaMailSenderImpl 类中获取 AuthenticationFailedException

spring - 无法导入Spring RepositoryRestResource

java - UI-Update 后 SpringLayout 中组件的宽度等于 0

Java IBM MQ 客户端已连接但未从队列获取消息

java - 如何将文件与 String java 中的文件完全一样保存

html - 在 div 中悬停缩放图像

html - 移动 chrome 上的 wow.js 动画仅在停止滚动时触发

具有不同位置(右侧或左侧或完整)的 HTML Div 列表

java - heroku Java oAuth 与 Salesforce