changes for servlet

This commit is contained in:
Karan Khanna 2018-05-20 13:00:25 +02:00
parent 8123ba6442
commit e375a00a09
2 changed files with 20 additions and 20 deletions

View File

@ -18,6 +18,11 @@
<artifactId>javax.servlet-api</artifactId> <artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet.version}</version> <version>${javax.servlet.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
@ -30,11 +35,6 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId> <artifactId>spring-test</artifactId>

View File

@ -25,9 +25,9 @@ public class EmployeeServlet extends HttpServlet {
Double salary = Double.parseDouble(request.getParameter("salary")); Double salary = Double.parseDouble(request.getParameter("salary"));
Employee employee = new Employee(id, name, department, salary); Employee employee = new Employee(id, name, department, salary);
String employeeJsonString = new Gson().toJson(employee);
PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter();
String employeeJsonString = new Gson().toJson(employee);
response.setContentType("application/json"); response.setContentType("application/json");
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
out.print(employeeJsonString); out.print(employeeJsonString);