View Full Version : Jsp with servlet

preethi A
05-03-2008, 10:43 AM
Hi ,
I am new to servlets.I am having a jsp page to login with username and password.I have to get the username and password in a servlet page using session.How to start with this?Any url or sample code .please suggest me.


05-06-2008, 03:43 PM
There is some good reading available on the net for the problem stated below:-




The code posted below is from Tomcat's , webapps examples, that is available on downloading it.

session.setAttribute and session.getAttribute are the two functions used as setter and getter for information from one jsp page to the other, in a session.

Source Code for Session Example

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SessionExample extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
PrintWriter out = response.getWriter();

HttpSession session = request.getSession(true);

// print session info

Date created = new Date(session.getCreationTime());
Date accessed = new Date(session.getLastAccessedTime());
out.println("ID " + session.getId());
out.println("Created: " + created);
out.println("Last Accessed: " + accessed);

// set session info if needed

String dataName = request.getParameter("dataName");
if (dataName != null && dataName.length() > 0) {
String dataValue = request.getParameter("dataValue");
session.setAttribute(dataName, dataValue);

// print session contents

Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = session.getAttribute(name).toString();
out.println(name + " = " + value);

07-25-2008, 10:13 PM

If you need a good servlets video tutorial, you can go here


If I Were A Boy
12-10-2008, 01:57 PM
The servlet you are accessing thruogh JSP should be configured in web.xml file

01-08-2009, 07:34 AM
You can do this using request.getParameter().
have a look at Servlet examples (http://www.jsptube.com) it has examples which will help you.