Write a Java Servlet to display a welcome message as a response to the web browser request for that servlet. Servlet should be stored at TOMCAT web server.

Standard

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;

import javax.servlet.http.*;

 

public class showMsg extends HttpServlet {

 

protected void doGet(HttpServletRequest request,

HttpServletResponse response) throws ServletException, IOException {

response.setContentType(“text/html”);

PrintWriter out = response.getWriter();

out.println(“<html><title></title><body>”);

out.println(“Welcome “);

out.println(“</body>”);

out.println(“</html>”);

}

}

capture

Advertisements

What is JavaServer Pages?

Standard

JavaServer Pages (JSP) is a technology for developing web pages that support dynamic content which helps developers insert java code in HTML pages by making use of special JSP tags, most of which start with <% and end with %>.

A JavaServer Pages component is a type of Java servlet that is designed to fulfill the role of a user interface for a Java web application. Web developers write JSPs as text files that combine HTML or XHTML code, XML elements, and embedded JSP actions and commands.

Using JSP, you can collect input from users through web page forms, present records from a database or another source, and create web pages dynamically.

JSP tags can be used for a variety of purposes, such as retrieving information from a database or registering user preferences, accessing JavaBeans components, passing control between pages and sharing information between requests, pages etc.