❮ Previous Next ❯

ServletResponse

The ServletResponse is an in-built interface coming from javax.servlet package containing various methods that enable a servlet to respond to the client requests. There are various methods of ServletResponse interface, such as:

Let's see a demo program :

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h2><u>Login Form:</u></h2><br><br>
<form action="MyServlet" method="get">
<table>
<tr><th>Username:</th><td><input type="text" name="uname">
<tr><th>Password:</th><td><input type="password" name="pass">
<tr><th><input type="submit" value="Submit"></th><td><input type="reset" value="Reset">
</table>
</form>

</body>
</html>

MyServlet.java:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
{
response.setContentType("text/html");

PrintWriter out=response.getWriter();

String s1=request.getParameter("uname");
String s2=request.getParameter("pass");

if(s2.equals("admin"))
out.println("Successfully Logged In");
else
out.println("Invalid Password");
}
}

web.xml:

<web-app>
<servlet>
<servlet-name>abc</servlet-name>
<servlet-class>java8s.MyServlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>abc</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
</web-app>


❮ Previous Next ❯

Follow Us




  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved