title: How to pass parameter from on servlet to another?
body: <p>I'm able to get parameters from the html file; but i'm not able to send those parameters to other Servlet..</p>
  
  <p>What exactly i want to do is, that get the user name and password in one servlet and then send those values to another servlet for authentication and then redirect accordingly....</p>
  
  <p>And i'm new to this I've tried many things blindly and not able to get the work done....</p>
  
  <p>This is my 1st Servlet:</p>
  
  <pre><code>public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException {
  response.setContentType("text/html");
  String uname=request.getParameter("uname");
  String pass=request.getParameter("pass");
  PrintWriter out=response.getWriter();
  if(uname!=null &amp;&amp; pass!=null){
      ServletContext sc=getServletContext();
      RequestDispatcher r=sc.getRequestDispatcher("/Authentication");
      response.sendRedirect("Authentication");
  } else {
      out.println("Error");
  }
  </code></pre>
  
  <p>And this is my 2nd Servlet:</p>
  
  <pre><code>public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException {
          PrintWriter out = response.getWriter();
          response.setContentType("text/html");
          String uname=(String)request.getAttribute("uname");
          String pass=(String)request.getAttribute("pass");
          int p=pass.hashCode();
          try{
              Class.forName("com.mysql.jdbc.Driver").newInstance();
          Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/aed","root","passwordmysql");
          Statement st=con.createStatement();
          ResultSet rs;
          rs=st.executeQuery("select * from logids where userName='" + uname + "' and pass='" + p +"'");
          if(rs.next()){
              response.sendRedirect("home.html"); 
          }else{
              response.sendRedirect("Error.html");
          }
          }
          catch(SQLException i){
              i.printStackTrace();
          } catch (InstantiationException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (IllegalAccessException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (ClassNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  </code></pre>
  
  <p>I'm new at this and i'm pretty sure i've done mistakes.....</p>