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?

Recommended Answers

All 4 Replies

There is existing tutorial on the top of JSP section why don't you read it...

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 {
		
	}

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.