Added messages feature via JSON as per step 3 of week 3#7
Added messages feature via JSON as per step 3 of week 3#7
Conversation
portfolio/pom.xml
Outdated
| <dependency> | ||
| <groupId>com.google.code.gson</groupId> | ||
| <artifactId>gson</artifactId> | ||
| <version>2.8.6</version> | ||
| </dependency> |
There was a problem hiding this comment.
nit - let's keep dependencies alphabetical by groupId and then artifactId
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.servlet.http.HttpServletResponse; | ||
|
|
||
| import java.util.ArrayList; |
There was a problem hiding this comment.
Can you run this file through the gist? Should fix these imports for us.
| import java.util.ArrayList; | ||
| import com.google.gson.Gson; | ||
|
|
||
| /** Servlet that returns some example content. TODO: modify this file to handle comments data */ |
There was a problem hiding this comment.
nit - remove this TODO comment, now that the class is handling comment data.
portfolio/src/main/java/com/google/sps/servlets/DataServlet.java
Outdated
Show resolved
Hide resolved
| /** Servlet that returns some example content. */ | ||
| @WebServlet("/data") | ||
| public class DataServlet extends HttpServlet { | ||
| List<String> messages = new ArrayList<>(); |
There was a problem hiding this comment.
Move this variable definition into the doGet method. If you define it at the class level, then every time someone refreshes your page, your code will add another 3 comments to the array. Eventually your server will OOM after so many visits.
There was a problem hiding this comment.
It seems doGet always returns the same messages, this could be made a constant ImmutableList instead.
There was a problem hiding this comment.
Oh oops I don't think it got changed, I'll quickly move the variable definition.
| /** Servlet that returns some example content. */ | ||
| @WebServlet("/data") | ||
| public class DataServlet extends HttpServlet { | ||
| List<String> messages = new ArrayList<>(); |
This pull request uses local memory to store comments, and allows them to be fetched with a GET request. The GET request returns the comment pairs in JSON format, and the webpage displays the comments upon page load.