Steps To Set Path For Tomcat
Steps To Set Path For Tomcat
Follow these steps to configure Apache Tomcat in Eclipse IDE and run a simple Java Servlet
program.
1. Open Eclipse IDE (Ensure you have Eclipse IDE for Java EE Developers).
2. Click on Window → Preferences.
3. Navigate to Server → Runtime Environments.
4. Click Add → Choose Apache Tomcat v9.0 (or your version).
5. Click Next, then browse and select the Tomcat installation folder (C:\apache-tomcat-
9.0.XX).
6. Click Finish and then Apply and Close.
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;
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html");
response.getWriter().println("<h2>Hello, Welcome to Java Servlet
Programming!</h2>");
}
}
xml
CopyEdit
<web-app>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>com.example.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
http://localhost:8080/MyServletApp/hello
css
Hello, Welcome to Java Servlet Programming!
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////
1ST HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
HELLO STUDENTS
</body>
</html>
2ND HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
text-align: center;
margin-top: 50px;
form {
display: inline-block;
padding: 20px;
border-radius: 10px;
background-color: #f9f9f9;
input, button {
margin: 10px;
padding: 8px;
font-size: 16px;
</style>
</head>
<body>
<form onsubmit="calculateSum(event)">
<label>Number 1:</label>
<label>Number 2:</label>
</form>
<h3 id="result"></h3>
<script>
function calculateSum(event) {
</script>
</body>
</html>