I am working on a JSP MVC web application. I am confused about Thread-Safe Servlet concept. Following is my code, please tell me is it thread safe or not. Also, tell me the reason that why it is thread-safe or not thread-safe.
JSP Code;
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Personal Profile</title>
</head>
<body>
<form id="PersonalData" method="post" action="PersonalDataServlet">
First Name:<input type="input" name="FirstNameField"><br>
Last Name:<input type="input" name="LastNameField"><br>
Email:<input type="input" name="EmailField">Without @ part<br>
<input type="Submit" value="Submit Data">
</form>
<br>
<br>
<br>
<%
out.print(request.getAttribute("FullName") + "\n");
out.print(request.getAttribute("EmailAddress"));
%>
</body>
</html>
Servlet Code;
package Servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import Model.WelcomeName;
@WebServlet("/PersonalDataServlet")
public class PersonalDataServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String FirstNameServlet;
String LastNameServlet;
String EmailServlet;
FirstNameServlet = request.getParameter("FirstNameField");
LastNameServlet = request.getParameter("LastNameField");
EmailServlet = request.getParameter("EmailField");
System.out.println(FirstNameServlet + "\n" + LastNameServlet + "\n" + EmailServlet);
WelcomeName WelcomeNameObject = new WelcomeName();
WelcomeNameObject.Fullname(FirstNameServlet, LastNameServlet, EmailServlet);
request.setAttribute("FullName", WelcomeNameObject.FullName);
request.setAttribute("EmailAddress", WelcomeNameObject.EmailAddress);
request.getRequestDispatcher("Profile.jsp").forward(request, response);
}
}
Other Class Which is used to the actual calculation or Business Logic
package Model;
public class WelcomeName {
public String FullName;
public String EmailAddress;
public void Fullname(String FirstName, String LastName, String Email) {
FullName = (FirstName + " " + LastName);
EmailAddress = (Email + "@gmail.com");
}
}