hai everybody,

i have a problem in jsp that i should access my application only by login. in my project when i give this url in my address bar "http://localhost:8080/jsp-examples/InvMgmt/test/stockrequisition.jsp". it directly goes to the stockrequisition page.

i dont know how to use the session variable. here i am sending stock requisition page please make a help for me.its urgent.

thanx in advance

<%@ page import="java.sql.*" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.PreparedStatement" %>



<html>
	<head>
		<script language="JavaScript" src="GCappearance.js"></script>
		<script language="JavaScript" src="GurtCalendar.js"></script>
		<link rel="stylesheet" href="calendar.css">
			<title>STOCK REQUISITION</title>
				<style type="text/css">
                  <!--
                    .style24 {font-family: Verdana, Arial, Helvetica, sans-serif; 

font-size: 12px; font-weight: bold; }
                    .style38 {font-size: 10px}
                    .style39 {font-family: Verdana, Arial, Helvetica, sans-serif; 

font-size: 12px; font-weight: bold; }
			
                  -->
                </style>


		<script language = "javascript">



function check()
		{
			if(document.frm1.n1.value=="")
			{
				alert("Please enter SR No");
				document.frm1.n1.focus();
			}
			else if(document.frm1.n2.value=="")
			{
				alert("Please enter Item ID");
				document.frm1.n2.focus();
			}
			else if(document.frm1.n3.value=="")
			{
				alert("Please enter SR Quantity");
				document.frm1.n3.focus();
			}
			else if(document.frm1.dataAreaTest.value=="")
			{
				alert("Please enter Date");
				document.frm1.dataAreaTest.focus();
			}
			else if(document.frm1.n4.value=="")
			{
				alert("Please enter SR Status");
				document.frm1.n4.focus();
			}
			else if(document.frm1.n5.value=="")
			{
				alert("Please enter From Party");
				document.frm1.n5.focus();
			}
			else if(document.frm1.n6.value=="")
			{
				alert("Please enter Remarks");
				document.frm1.n6.focus();
			}
			else
			{
			document.location.href=("stockinsert.jsp?srno=" + 

document.frm1.n1.value + "&itemid="+document.frm1.n2.value + "&srqty="+ 

document.frm1.n3.value + "&date=" + document.frm1.dataAreaTest.value + "&srstatus=" 

+ document.frm1.n4.value + "&fromparty=" + document.frm1.n5.value + "&remarks=" + 

document.frm1.n6.value);
			alert("Stock Requistion is Created");
			}
		}
		
		function reset()
        {
            frm1.n1.value="";
            frm1.n2.value="";
            frm1.n3.value="";
            frm1.n4.value="";
            frm1.n5.value="";
            frm1.n6.value="";
            frm1.n7.value="";
            frm1.n1.focus();
        }
		
function cancel()
{
if(document.frm1.n1.value=="")
{
alert("Please enter SRNo to search");
document.frm1.n1.focus();
}
else
{

document.location.href=("stockdelete.jsp?srno=" + document.frm1.n1.value);


}
}


		</script>
	</head>
	<body background="images/WSBackground_Songs1.jpg">
		<center><h2>STOCK REQUISTION</h2></center>
        <center>
			<form name="frm1" action="stockinsert.jsp" method="post">
            <center>
				<table width="800" border="0" cellspacing="5" 

cellpadding="0">
					<center>
                        <tr>
                           <td width="900" >        <table width="800" 

align="center" border="0" cellspacing="5" cellpadding="2">
								<tr>
									<td><span 

class="style39"></span></td>      
									<td><span 

class="style39"></span></td>
									

<td>&nbsp;</td>
                                    <td><span class="style39"></span></td>
                                    <td>&nbsp;</td>     
		<%
			Connection con=null;
			Statement st=null;
			ResultSet rs=null;
			try 
			{
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				con = DriverManager.getConnection

("jdbc:odbc:invent");
				String query="select max(SR_No) from 

Stock_Requistion";
				st=con.createStatement();
				rs=st.executeQuery(query);
				while(rs.next())
				{
		  %>	 
                                                     <td  align="left"><span 

class="style24">SR No: </span></td>
                                                    <td><input name="n1" type="text" 

title = "Please enter the SR No in the series of 1000...
For Eg: 1001" value="<%=rs.getInt(1)+1%>"></td>
		  <%
		} 
		 
	 } catch (Exception e) {
        //Handle exception
        System.out.println(e);
    } finally {
        try {
            rs.close();
            st.close();            
            con.close();
        } catch (Exception e) {
            //Handle exception
        }
	}
			  %>                                             
                                                   <td><span 

class="style39"></span></td>
                                                                                     

          
                                                 <td><span 

class="style39"></span></td>
                                                  <td>&nbsp;</td>
 <td><span class="style39"></span></td>
                                                     <td>&nbsp;</td>
                                                   <td align="left"><span 

class="style24">Item ID: </span></td>
                                                   <td><input name="n2" type="text" 

title= "Please enter the Item ID like the example given below
For Eg: i001"></td>
											

		
                                                  <td><span 

class="style39"></span></td>
                                                    <td><span 

class="style39"></span></td>
 <td align="left"><span class="style24">Requested Delivery Date:</span></td>
<td>
    <script language="JavaScript">
<!--		
var GC_SET_0 = {
	'appearance': GC_APPEARANCE,
	'dataArea' : 'dataAreaTest'
}
new gCalendar(GC_SET_0);
//-->
</script></td>           
</tr>
                 </tr>            

    
                 <tr>
<td><span class="style39"></span></td>
                                      <td><span class="style39"></span></td>
                                                     <td>&nbsp;</td>
                                              <td><span class="style39"></span></td>
                                                    <td>&nbsp;</td>
                                                  <td align="left"><span 

class="style24">SR Quantity: </span></td>
                                                  <td><input name="n3" type="text" 

title="Please enter numeric values"></td>
                                                   <td><span 

class="style39"></span></td>
                                                  <td><span 

class="style39"></span></td>

                        <td><span class="style39"></span></td> <td>&nbsp;</td>     
                        <td><span class="style39"></span></td>
                                                                                   
                         <td align="left"><span class="style24">SR Status: 

</span></td>
                         <td><input name="n4" type="text" title="Please enter the SR 

Status like the example given below
For Eg: active or inactive"></td>
 <td><span class="style39"></span></td>
<td><span class="style39"></span></td>
                       </tr>
<tr>
<td><span class="style39"></span></td>
                                                    
<td><span class="style39"></span></td>
                                                     <td>&nbsp;</td>
<td><span class="style39"></span></td>
                                                     <td>&nbsp;</td>
                       <td align="left"><span class="style24">From 

Party:</span></td>
                      <td><input name="n5" type="text" title= "Please enter the From 

Party like the example given below
For Eg: s001"></td>
 <td><span class="style38"></span></td>
<td><span class="style39"></span></td>
                     
  
<td><span class="style39"></span></td>
                                                     <td>&nbsp;</td>
<td><span class="style39"></span></td>
                                                     
            <td align="left"><span class="style24">Remarks: </span></td>
            <td><input name="n6" type="textfield" title= "Please enter the Remarks 

like the example given below
For Eg: success or failed"></td>
             <td><span class="style39"></span></td>

           </tr>
</center></table>
<table>
<tr>


           
</table>

       <br>
   <center>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="btn"type="button" value="CREATE SR" onClick="check()" >
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;<INPUT TYPE="reset" onClick=reset() value="RESET">&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;<INPUT TYPE="button" name="can" onClick=cancel() value="CANCEL 

SR"></center>
  </center> 
</center>
</form>

</body>

</html>

Recommended Answers

All 4 Replies

Redo from start.
Not urgent.
Rubbish code.

hi jwenting,
if u dont like to give any solution be quiet. dont scold any body. the code is working correctly.it is not a rubish code.

It is rubbish. It is fundamentally flawed by design.
If you don't want to hear advice you don't like, don't ask questions.

jwenting is correct, you are using JSP for incorect purpose. Database connection have to be managed through servlet not JSP as you did. It is still possible by JSP but that is wrong

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.