i have to invoke a servlet from jsp and pass many variables to the servlet.
my jsp code is::

<%@ page import="java.io.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page import="java.util.*" %>

<%
	String flag1=(String)session.getAttribute("flag");
	out.println(flag1);
	if(flag1=="signin")
	{	
		int ac_id=0;
		String acc_no=null,no=null;
		String offer_id=null,classes=null;
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		String JDBC_DRIVER = "com.mysql.jdbc.Driver";
		String DATABASE_URL = "jdbc:mysql://localhost/paymentenabler";
		Connection connection2;
		
		try
		{
			
			Class.forName( "com.mysql.jdbc.Driver" );
			connection2 = DriverManager.getConnection( DATABASE_URL,"root","");
			Statement statement1=connection2.createStatement();
			ResultSet columns1=statement1.executeQuery("select ac_id from login where 

username='"+username+"' and password='"+password+"'");
			if(columns1.next())
				ac_id = columns1.getInt("ac_id"); 
			else
				out.println("You are not a registered user.Please Sign up!!");
			out.println("ac_id is:"+ac_id);
			columns1.close();
			statement1.close();
			Statement statement2=connection2.createStatement();
			ResultSet columns2=statement2.executeQuery("select acc_no from account where 

ac_id='"+ac_id+"'");
			if(columns2.next())
				acc_no= columns2.getString("acc_no"); 
			//session.setAttribute("acc_no",acc_no);	
			out.println(acc_no);
			columns2.close();
			statement2.close();
			connection2.close();
		}catch (Exception e){
			out.println(e);
		}finally{}

		
		offer_id=(String)session.getAttribute("offer_id");
		classes=(String)session.getAttribute("cat2");
		no=(String)session.getAttribute("seats");
		out.flush();
		%>
		<jsp:forward page="/serv12" >
   		<jsp:param name="username" value="<% = username % >" />
	                 <jsp:param name="password" value="<% = password % >" />
		<jsp:param name="offer_id" value="<% =offer_id%>" />
		<jsp:param name="classes" value="<%=classes%>" />
		<jsp:param name="acc_no" value="<%=acc_no%>" />
		<jsp:param name="no" value="<%=no%>" />
		</jsp:forward>
<%  
	}
	else 
	{	
		int ac_id=0;
		String acc_no1=null,no=null;
		String date=null,time=null,classes=null;
		String fi_id=request.getParameter("fi");
		acc_no1=request.getParameter("account_no");
		String acc_name=request.getParameter("account_name");
		String username1=request.getParameter("user_name");
		String password1=request.getParameter("password1");
		String password2=request.getParameter("password2");
		if(password1!=password2)
			out.println("Please confirm the password correctly");
		else
		{
			String JDBC_DRIVER = "com.mysql.jdbc.Driver";
			String DATABASE_URL = "jdbc:mysql://localhost/paymentenabler";
			Connection connection2;
		
			try
			{
				
				Class.forName( "com.mysql.jdbc.Driver" );
				connection2 = DriverManager.getConnection( DATABASE_URL,"root","");
				Statement statement1=connection2.createStatement();
				ResultSet columns1=statement1.executeQuery("select ac_id from account where 

acc_no='"+acc_no1+"' and fi_id='"+fi_id+"'");
				if(columns1.next())
					ac_id = columns1.getInt("ac_id"); 
				else
					out.println("This account no.in the mentioned bank does not exist!!");
				out.println("ac_id is:"+ac_id);
				columns1.close();
				statement1.close();
				
				Statement statement2=connection2.createStatement();
				ResultSet columns2=statement2.executeQuery("select acc_no from account where 

ac_id='"+ac_id+"'");
				if(columns2.next())
					acc_no1= columns2.getString("acc_no"); 
				//session.setAttribute("acc_no",acc_no);	
				out.println(acc_no1);
				columns2.close();
				statement2.close();
				connection2.close();
			}catch (Exception e){
				out.println(e);
			}finally{}
		}
	}
	
%>

and the servlet code is::

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



public class try1 extends HttpServlet{

 private static final String[] majorNames = {
    "",
    " thousand",
    " million",
    " billion",
    " trillion",
    " quadrillion",
    " quintillion"
    
  };

  private static final String[] tensNames = {
    "",
    " ten",
    " twenty",
    " thirty",
    " fourty",
    " fifty",
    " sixty",
    " seventy",
    " eighty",
    " ninety"
    
    };

  private static final String[] numNames = {
    "",
    " one",
    " two",
    " three",
    " four",
    " five",
    " six",
    " seven",
    " eight",
    " nine",
    " ten",
    " eleven",
    " twelve",
    " thirteen",
    " fourteen",
    " fifteen",
    " sixteen",
    " seventeen",
    " eighteen",
    " nineteen"
    
    };

  private String convertLessThanOneThousand(int number) 
  {
    String soFar;

    if (number % 100 < 20){
        soFar = numNames[number % 100];
        number /= 100;
       }
    else {
        soFar = numNames[number % 10];
        number /= 10;

        soFar = tensNames[number % 10] + soFar;
        number /= 10;
       }
    if (number == 0) return soFar;
    return numNames[number] + " hundred" + soFar;
  }

  public String convert(int number) 
  {
    /* special case */
	  
    if (number == 0) { return "zero"; }

    String prefix = "";

    if (number < 0) 
    {
        number = -number;
        prefix = "negative";
    }

    String soFar = "";
    int place = 0;

    do 
    {
      int n = number % 1000;
      if (n != 0){
         String s = convertLessThanOneThousand(n);
         soFar = s + majorNames[place] + soFar;

        }
      place++;
      number /= 1000;
      } while (number > 0);
      return (prefix + soFar).trim();
  }
String user_name;
String password;
String acc_no;
String date;
String time;
String classes;
int no1;
int left;
int amt;
int op_id;
String no;
public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException{
	                 response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		pw.println("<form action=\"serv12\" method=\"post\">");
		int available=0;
		//int op_id=0;
		int price=0;
		user_name=request.getParameter("T4");
		password=request.getParameter("T5");
		acc_no=request.getParameter("T2");
		date=request.getParameter("T6");
		time=request.getParameter("T7");
		classes=request.getParameter("T8");
		no=request.getParameter("T9");
		no1=Integer.parseInt(no);

		pw.println("<HTML>");
		pw.println("<HEAD>");
		pw.println("<TITLE>Servlet Testing </TITLE>");
		pw.println("</HEAD>");
		pw.println("<BODY>");
								
		pw.print("<p><b>Available Seats :&nbsp;&nbsp;&nbsp;");

		String JDBC_DRIVER = "com.mysql.jdbc.Driver";
		String DATABASE_URL = "jdbc:mysql://localhost/paymentenabler";
		Connection connection2;
		try
		{
			Class.forName( "com.mysql.jdbc.Driver" );
			connection2 = DriverManager.getConnection( DATABASE_URL,"root","");
			Statement statement1=connection2.createStatement();
			ResultSet columns1=statement1.executeQuery("select seats_available,op_id,price from offer_price where offer_id in(select offer_id from offering where date='"+date+"' and start_time='"+time+"') and pp_id in(select pp_id from pricing_plan where classes like '"+classes+"')");
                                               
			while(columns1.next()){ 
				  available= columns1.getInt("seats_available"); 
				  op_id=columns1.getInt("op_id");
				  price=columns1.getInt("price");
				   pw.println(available);
			}
			pw.println("</p>");		
			pw.println("<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>");

			if(no1>available)
				pw.println("<b>Sorry!!tickets not available!!</b>");
			else
			{
				int ac_id=0;
				String status="";
				int bal=0;
				amt=no1*price;
				Statement statement4=connection2.createStatement();
				ResultSet columns3=statement4.executeQuery("select ac_id,amt_available,status from account where acc_no like '"+acc_no+"'");
				if(columns3.next()==false)
					pw.println("You are not applicable to book tickets as you are not an account holder in the banks we have tied up with.");
				else
				{
						  ac_id= columns3.getInt("ac_id"); 			
						  bal=columns3.getInt("amt_available");
						  status=columns3.getString("status");
						  pw.println("ac_id is:"+ac_id);	
						  pw.println("status is:"+status);
					if(status.equalsIgnoreCase("active"))
					{
								
						Statement statement2=connection2.createStatement();
						statement2.executeUpdate("update account set status='inactive' where ac_id='"+ac_id+"'");
						statement2.close();
						if(bal<amt)
							pw.println("Sorry,Insufficient Balance");
						else
						{
							left=available-no1;
							int ch=amt;
							String num1=this.convert(ch);
							pw.println("THE NUMBER IN STRING FORMAT");
							pw.println("<form>");
							pw.println("<H3>"+ num1+"</H3>" );
							//pw.println("</form>");
							pw.println("<H1>Do you want to continue?</H1>");
							//pw.println("<a href=\"serv11\">");
							pw.println("<p><input type=\"submit\" value=\"Submit\"></p>");
							//pw.println("</a>");				

							pw.println("</p>");
							pw.println("</form>");
							pw.println("</BODY>");
							pw.println("</HTML>");
							
					
						statement4.close();

						
				
					}	
				}else
				{
					pw.println("Your request is still in progress.Kindly wait....");}
			}
			statement1.close();
			connection2.close();
		}
		}catch (Exception e){
			pw.println(e);
		}finally{}
	}

public void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException{
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		pw.println("<p><img border=\"0\" src=\"e3.JPG\" width=\"428\" height=\"86\"></p>");
		pw.println("<p><a href=\"serv8\">");
		pw.println	("<img border=\"0\" src=\"HOME2.JPG\" width=\"91\" height=\"19\"></a>&nbsp;&nbsp;");
		pw.println("<a href=\"about_us.htm\">");
		pw.println("<img border=\"0\" src=\"ABOUT%20US.JPG\" width=\"73\" height=\"19\">");
		pw.println("</a>&nbsp;&nbsp;");
		pw.println("<a href=\"serv9\">");
		pw.println("<img border=\"0\" src=\"BOOK.JPG\" width=\"73\" height=\"19\">&nbsp;&nbsp;");
		pw.println("</a>&nbsp;&nbsp;");
		pw.println("<a href=\"serv7\">");
		pw.println("<img border=\"0\" src=\"MOVIES.JPG\" width=\"73\" height=\"19\"></a></p>");
		pw.println("<p><font color=\"#0000FF\" size=\"4\"><b>Book Tickets</b></font></p>");
		pw.println("<p><img border=\"0\" src=\"ticket.jpg\" width=\"271\" height=\"221\"></p>");
		//pw.println("<form action=\"serv11\" method=\"get\">");
		try
		{
			String DATABASE_URL = "jdbc:mysql://localhost/paymentenabler";
			Connection connection2;
			Class.forName( "com.mysql.jdbc.Driver" );
			connection2 = DriverManager.getConnection( DATABASE_URL,"root","");
			
	/*		String user_name=request.getParameter("user_name");
			pw.println(user_name);
			String password=request.getParameter("password");
			pw.println(password);
			String acc_no=request.getParameter("acc_no");
			pw.println(acc_no);
			String date=request.getParameter("date");
			pw.println(date);
			String time=request.getParameter("time");
			pw.println(time);
			String classes=request.getParameter("classes");
			pw.println(classes);
			String left1=request.getParameter("left");
			int left=Integer.parseInt(left1);
			pw.println(left);
			String op_id1=request.getParameter("op_id");
			int op_id=Integer.parseInt(op_id1);
			pw.println(op_id);
			
			String amt1=request.getParameter("amt");
			int amt=Integer.parseInt(amt1);
			pw.println(amt);*/
			int bal=0;
			int ac_id=0;
			int balance=0;
			int available=0;
			int bal_update=0;
			int pending_id=0;
			int amount=0;
			Statement statement4=connection2.createStatement();
			ResultSet columns3=statement4.executeQuery("select ac_id,amt_available from account where acc_no like '"+acc_no+"'");
			while(columns3.next()){ 
				  ac_id= columns3.getInt("ac_id"); 					
				  bal=columns3.getInt("amt_available");
				  pw.println("ac_id is:"+ac_id);			  
			}
					
			Statement statement2=connection2.createStatement();
			statement2.executeUpdate("update offer_price set seats_available='"+left+"' where op_id='"+op_id+"'");
			statement2.close();
			Statement statement3=connection2.createStatement();
			ResultSet columns2=statement3.executeQuery("select seats_available from offer_price where offer_id in(select offer_id from offering where date='"+date+"' and start_time='"+time+"') and pp_id in(select pp_id from pricing_plan where classes like '"+classes+"')");
			while(columns2.next()){ 
				available= columns2.getInt("seats_available"); 
				pw.println("The no. of seats left are:"+available);
			}
			statement3.close();
		                 Statement statement5=connection2.createStatement();
			statement5.executeUpdate("insert into pending_j values(null,'"+ac_id+"','"+op_id+"','"+no1+"','"+user_name+"','"+password+"','"+bal+"','"+amt+"','waiting')");
			statement5.close();
			Statement statement1=connection2.createStatement();
			ResultSet columns4=statement1.executeQuery("select pending_id,balance,amount,status from pending_j where status='waiting'");
			while(columns4.next()){ 
				balance= columns4.getInt("balance"); 
				amount=columns4.getInt("amount");
				pending_id=columns4.getInt("pending_id");
				bal_update=balance-amount;
				Statement statement7=connection2.createStatement();
				statement7.executeUpdate("update account set amt_available='"+bal_update+"' where ac_id='"+ac_id+"'");
				statement7.close();
				Statement statement8=connection2.createStatement();
				statement8.executeUpdate("update pending_j set status='processed' where pending_id='"+pending_id+"'");
				statement8.close();
				Statement statement9=connection2.createStatement();
				statement9.executeUpdate("update account set status='active' where ac_id='"+ac_id+"'");
				statement9.close();
			}
			pw.println("The no. of seats left are:"+available+"\nYour transaction is processed.You have to login again to book another ticket.");
			statement3.close();
			connection2.close();
		}catch (Exception e){
			pw.println(e);
		}finally{}
	}

}

im not getting any syntax error but its not going to the servlet "serv12".My serv12 is in the same folder as the jsp page.
Please tell me where im going wrong.
Thanks in advance.
Urgent!!please help!!

This article has been dead for over six months. Start a new discussion instead.