[英]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.