this is a very noob question. I have a project to do that exemplifies the use of RESTFUL APIs. I am using java spring + MySQL and JSPs for front-end. My question is this. Does HttpServletRequest
use 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
. If I swap it to @RestController
, it stops working. 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:
<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). RESTful web-services used when the client is some other application accepting data responses (it maybe the JavaScript in browser or some other application).
I have the controller class adnotated with @Controller. If I swap it to @RestController, it stops working.
If you swap it to @RestController
the response intended to be JSON, or 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).
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.
Does HttpServletRequest use REST?
REST means Representational state transfer , and it's architectural style of the application. HttpServletRequest
it's just a requested body from current API. It can be used as either in RESTful or in non-RESTful servces.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.