简体   繁体   English

HttpServletRequest-API REST

[英]HttpServletRequest - API REST

this is a very noob question. 这是一个非常菜鸟的问题。 I have a project to do that exemplifies the use of RESTFUL APIs. 我有一个项目可以说明RESTFUL API的使用。 I am using java spring + MySQL and JSPs for front-end. 我在前端使用Java Spring + MySQL和JSP。 My question is this. 我的问题是这个。 Does HttpServletRequest use REST ? HttpServletRequest是否使用REST For example, I have one controller with this method in it: 例如,我有一个使用此方法的控制器:

  @RequestMapping(value = "/list_events", method = RequestMethod.GET)
public String navigateToEventList(HttpServletRequest request){

    request.setAttribute("events",eventService.getAll());
    return "listevents";
}

I have the controller class annotated with @Controller . 我有@Controller注释的控制器类。 If I swap it to @RestController , it stops working. 如果我将其交换到@RestController ,它将停止工作。 So, am I using rest in this method for example? 那么,我是否在这种方法中使用了休息? And if not, what should I use? 如果没有,我应该怎么用?

And in my jsp file this is what I have for example: 在我的jsp文件中,例如:

 <c:forEach var="event" items="${events}">

        <tr>

            <td>${event.id}</td>
            <td>${event.title}</td>
            <td>${event.description}</td>
            <td>${event.type}</td>
            <td>${event.date}</td>
            <td>${event.location}</td>

        </tr>
    </c:forEach>

JSP is used when the client needs to display the contents in HTML (web-browser). 当客户端需要以HTML(Web浏览器)显示内容时,将使用JSP。 RESTful web-services used when the client is some other application accepting data responses (it maybe the JavaScript in browser or some other application). 当客户端是接受数据响应的某些其他应用程序(可能是浏览器中的JavaScript或某些其他应用程序)时使用的RESTful Web服务。

I have the controller class adnotated with @Controller. 我用@Controller标注了控制器类。 If I swap it to @RestController, it stops working. 如果我将其交换到@RestController,它将停止工作。

If you swap it to @RestController the response intended to be JSON, or XML. 如果将其交换到@RestController则响应旨在为JSON或XML。 You can achieve the same result with annotation @Controller your calss and @ResponseBody on each of the methods (if you need mix of REST and non-REST responses). 您可以在每个方法上使用注解@Controller@ResponseBody来实现相同的结果(如果需要混合使用REST和非REST响应)。

What you're doing now is returning the HTML/JSP page to your browser, and it's not a RESTful web-service - it's the first case I described above. 您现在正在做的是将HTML / JSP页面返回到浏览器,它不是RESTful Web服务-这是我在上面描述的第一种情况。

Does HttpServletRequest use REST? HttpServletRequest是否使用REST?

REST means Representational state transfer , and it's architectural style of the application. REST表示代表性状态转移 ,它是应用程序的体系结构样式。 HttpServletRequest it's just a requested body from current API. HttpServletRequest它只是当前API的请求主体。 It can be used as either in RESTful or in non-RESTful servces. 它可以在RESTful服务或非RESTful服务中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 到达Java REST API 后,HttpServletRequest 可以为空吗? - Can HttpServletRequest be null after arriving in Java REST API? 如何在 Spring 引导中将 HttpServletRequest 标头转发到另一个 REST API - How to forward HttpServletRequest headers to another REST API in Spring Boot 将HttpServletRequest注入rest服务 - Inject HttpServletRequest into rest service 将 HttpServletRequest 传递给另一个 API controller - Passing HttpServletRequest to another API controller 如何测试使用HttpServletRequest的休息服务? - How to test a rest service that uses a HttpServletRequest? HttpServletRequest getCookies()始终返回null的Jersey Api - HttpServletRequest getCookies() always returns null Jersey Api Reactive Spring 不支持 HttpServletRequest 作为 REST 端点中的参数? - Reactive Spring does not support HttpServletRequest as parameter in REST endpoint? 旧servlet-api-2.3.jar上的HttpServletRequest注销 - HttpServletRequest logout on old servlet-api-2.3.jar HttpservletRequest 仅在 refreshtoken api 调用中未在后端采用更新的刷新令牌 - HttpservletRequest not taking newer refreshtoken at backend side in only refreshtoken api call 在IntelliJ Idea Gmail API项目中找不到HttpServletRequest类 - HttpServletRequest class not found in IntelliJ Idea Gmail API project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM