0

Hello. I wish to create a servlet which checks if the entered username and password are correct.If yes..message hello else go back to page showing error message.

I know the settings for tomcat. i know the basic code for servlet.I also know i need http servlet .I will be using html code. I am unsure about the html can anybody help me to read entered values for username and password.(input type=text name=username...what further?

2
Contributors
4
Replies
11
Views
7 Years
Discussion Span
Last Post by poojasweetgirl
-1

I did not get what u refered to. But after some search i learned the getParameter method

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletConfig;
import java.io.*;


public class SampleHServlet1 extends HttpServlet {
	
    public void init(ServletConfig config) throws ServletException{
    	
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse 

response) throws ServletException, IOException {
		 
		System.out.println("We are in Do get Method");

		response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head>");
         out.println("<title>" + "helloworld.title" + "</title>");
        out.println("</head>");
        out.println("<body bgcolor=\"gray\">");
		
        out.println("<form action='SampleHServlet1' method='get'>");
        out.println("<input type=text name='username'>");
         String s1=request.getParameter('username');
        if(s1=='pooja')
       out.println("welcome");
       out.println("</form>");
        out.println("</body>");
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse 

response) throws ServletException, IOException {
		
	}

}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.