Servelt WebApp

To build a sample servlet web app:

  • mvn archetype:generate

select all, copy paste into a text editor, find "J2EE 1.4 web application archetype", note the number, type it in terminal in the interactive mode

specified groupId: edu.emich

specified artifact name: vq

fill out the rest of their questions

cd vq

mvn compile

mvn package

rename .war file in the target directory into something shorter

copy war into tomcat/webapps.

In the browser, open tomcat:8080/filename.war (replace filename with the actual filename of your war file)

    • Copy the whole folder into Eclipse, import from archive or folder

  • right-click on project->properties, search for "compliance" and change JRE to JavaSE-1.8

  • it will show an error message in Problems view, saying different version of JDK (or java) and suggest quick fixes. Right click on the problem -> Quick fix, choose the one that says some thing along the lines of "increase version to 1.8"

  • Right-click on the project -> New -> other, type Servlet. Just give it a name (e.g., TestServlet), do not change any mappings. It automatically adds mappings to web.xml.

  • add this to index.jsp:

<br>

<form action="EchoServlet" method="get">

Enter your name: <input type="text" name="yourName" size="20">

<input type="submit" value="Call EchoServlet" />

</form>

<br>

  • add this inside the doGet method of TestServlet.java:

response.getWriter().append(request.getParameter("yourName")

+ " this TestServlet servlet was changed by Andrii! Served at: ")

.append(request.getContextPath());

rebuild, redeploy.