0% found this document useful (0 votes)
10 views2 pages

Agiled

Uploaded by

pranay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Agiled

Uploaded by

pranay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Create the Servlet

Create a new servlet that will handle your backend logic.

java

Copy code

package com.example;

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("/myservlet")

public class MyServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

request.setAttribute("message", "Hello from Servlet!");

request.getRequestDispatcher("/index.jsp").forward(request, response);

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

// handle POST request


}

4. Create JSP Files

Inside your src/main/webapp directory, create a JSP file (index.jsp):

jsp

Copy code

<!DOCTYPE html>

<html>

<head>

<title>My JSP Page</title>

</head>

<body>

<h1>${message}</h1>

<form action="myservlet" method="post">

<input type="text" name="data" />

<input type="submit" value="Submit" />

</form>

</body>

</html>

You might also like