Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Jsp with servlet

    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.

    Thanks.

  • #2
    New Coder
    Join Date
    Aug 2007
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post
    There is some good reading available on the net for the problem stated below:-

    http://forum.java.sun.com/thread.jsp...sageID=4033625

    http://java.sys-con.com/read/37125.htm

    http://java.sun.com/developer/online.../contents.html

    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.

    Code:
    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
        {
            response.setContentType("text/html");
            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);
            }
        }
    }

  • #3
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Servlets tutorials

    Hi,

    If you need a good servlets video tutorial, you can go here
    http://www.sharmanj.com

    Thanks,
    Sharad.

  • #4
    New Coder
    Join Date
    Nov 2008
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The servlet you are accessing thruogh JSP should be configured in web.xml file

  • #5
    Regular Coder
    Join Date
    Jan 2009
    Location
    india
    Posts
    145
    Thanks
    0
    Thanked 5 Times in 5 Posts
    You can do this using request.getParameter().
    have a look at Servlet examples it has examples which will help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •