aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes calling a java Script file into the Jsp  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "calling a java Script file into the Jsp  " Watch "calling a java Script file into the Jsp  " New topic
Author

calling a java Script file into the Jsp

Amar Deep Singh Chaudhary
Ranch Hand

Joined: Dec 26, 2006
Posts: 49
hi ranchers can anybody tell me that how we can call a java script function into our jsp file which is saved into another java script file.please give me a code example of this thing.thanks

Amar Deep Singh Chaudhary


"A thinking mind never dies"
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

Since JSP creates an HTML file to send the the browser, then you'd do this the exact same way that you would in any HTML file.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Amar Deep Singh Chaudhary
Ranch Hand

Joined: Dec 26, 2006
Posts: 49
hi
thanks for suggestion.
i have created a page in jsp and shows the contents into the form of a table in a form say form1 in this table i am showing the contents of the current database and providing the uption for changing the contents in the second column of the table by providing the appropriate text boxes and a button is given to submit to information to the server again before sending the information i want to check the fields that have the coorect input at the client side.For this purpose i have write the script function in the head section and calling this on submit of the form but the script code is not working please help me .I am giving the code here.if there is any error then tell me.
Thanks in Advance.


<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,java.util.*,java.lang.*,javax.servlet.*,javax.servlet.http.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Updation of The Employee Record</title>
<style type="text/css">
<!--
.style1 {
color: #FF9900;
font-weight: bold;
}
body,td,th {
color: #000000;
font-weight: bold;
}
body {
background-color: #339999;
}
-->
</style>
<script language="javascript">
function isPositive(str)
{
position=1;
pattern="0123456789.";
i=0;
while(position==1 && i<str.length){
position=0;
for(var j=0;j<pattern.length;j++)
{

if(str.charAt(i)==pattern.charAt(j))
{
position=1;

break;
}
}
i++;
}

if(position==0)
return false;


return true;
}


function isDate(str)
{
if(str.length!=10 || str.charAt(2)!="/" || str.charAt(5)!="/" || !isPositive(str.substring(0,2)+str.substring(3,5)+str.substring(6,10)))

return false;
var d=str.substring(0,2)-0;
var m=str.substring(3,5)-0;
var y=str.substring(6,10)-0;
if(d==0 || m==0 || y==0)
return false;
if(m>12)
return false;
if(m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12)
var dmax=31;
else if(m==4 || m==6 || m==9 || m==11)
dmax=30;
else if((y%400==0) || (y%4==0 && y%100!=0))
dmax=29;
else
dmax=28;

if(d>dmax)
return false;
if(y>2007)
return false;
return true;
}

function isEmpty(str1)
{
if(str1=="" || str1==null)
return true;
return false;
}
function validateInput(password1,E_mail1,designation1,dateofjoin1,salary1,mobile1,name1,address1,gender1)
{

if(isEmpty(password))
{alert("PassWord can't be left Blank","Pass-Word Empty Error");
return false;
}

if(isEmpty(email))
{alert('E-Mail Id must have a Value ');
return false;
}
if(E_mail.indexOf('@',0)==-1)
{
alert('E-Mail Id is not Valid please Correct it to proceed it again!');
return false;
}
if(E_mail.indexOf('.',0)==-1)
{
alert('E-Mail Id is not Valid please Correct it to proceed it again!');
return false;
}

if(isEmpty(designation))
{alert('Please Select a Value for designation Field ');
return false;
}
if(isEmpty(dateofjoin))
{alert(" Date of Join Field can't be left Blank");
return false;
}

if(!isDate(dateofjoin))
{
alert("Date of Join Field is not Valid");
return false;
}
if(isEmpty(salary) || !isPositive(salary))
{
alert("Salary Value is not Valid");
return false;
}
if(isEmpty(mobile) || mobile.length<10 || !isPositive(mobile))
{
alert("Mobile Number is not Valid");
return false;
}
if(isEmpty(name))
{alert(" Name can't be left Blank");
return false;
}
if(isEmpty(address))
{alert(" Address can't be left Blank");
return false;
}
if(isEmpty(gender1))
{alert(" Please Specify the Gender of the Employee");
return false;
}
return true;
}
</script>
</head>

<body>
<h4><span class="style1"><em><marquee>A Thinking Mind Never Dies </marquee></em>!</span></h4>
<img src="impetuslogo.jpg" width="986" height="104">
<% if(session==null)
out.print("Sorry Dear Either You Lost your Session For You Trying To Make Fool The Server.you are not an Authorized User To View This Page.<br>Your Ip Address "+request.getRemoteHost()+"Is Logged");
else if(session.getId().equals((String)session.getAttribute("sessionid")))
{
String emp_id=request.getParameter("empid");
String name=(String)session.getAttribute("name");
out.print("Hello Mr."+name+".You are here to update the Record of the Employee ID No-"+emp_id +"Please read the last records Values and entered the new Values in the Appropiate fields.The Employee Id Field Is an Softtware Generated Field So Don't Try to Update The Employee Id");
Statement st;
ResultSet rs;
PreparedStatement st1;
try{
Connection con=(Connection)session.getAttribute("connection");

st=con.createStatement();
rs=st.executeQuery("select * from employee where emp_id='"+emp_id +"'");
if(rs.next())
{
String emp_id1=rs.getString("emp_id");
String password=rs.getString("password");
String Email_id=rs.getString("Email_id");
String designation=rs.getString("designation");
String Gender=rs.getString("Gender");
String date_of_join=rs.getString("date_of_join");
float salary=rs.getFloat("salary");
String mobile_no=rs.getString("mobile_no");
String Name=rs.getString("Name");
String Address=rs.getString("Address");
String edited_by=rs.getString("edited_by");
String date_of_modification=rs.getString("date_of_modification");
out.print("<form method='post' action='/impetus/updaterecord' name='form2' onSubmit='return validateInput(this.password1.value,this.E_mail1.value,this.designation1.value,this.dateofjoin1.value,this.salary1.value,this.mobile1.value,this.name1.value,this.address1.value,this.gender1.value);'>");
out.print("<table border align='center'><tr><th>Field Name</th><th>OLD RECORD VALUES</th><th>NEW RECORD VALUES</th></tr>");
out.print("<tr><td> Employee ID</td><td>"+emp_id1+"</td><td><input name='emp_id1' type='text' size='30' readonly='true' value='"+emp_id1+"'></td></tr>");
out.print("<tr><td>Password </td><td>"+password+"</td><td><input name='password1' type='text' size='20' maxlength='25'></td></tr>");
out.print("<tr><td>E-Mail Address </td><td>"+Email_id+"</td><td><input name='E_mail1' type='text' size='30' maxlength=50 onFocus='return Empty(form2.password1.value);'> </td></tr>");
out.print("<tr><td>Designation </td><td>"+designation+"</td><td> <select name='designation1' size='1' ><option value='Software Engg'>Software Engg</option><option value='Software Developer'>Software Developer</option><option value='java Trainee'>java Trainee</option>");
out.print("<option value='.net trainee'>.net trainee</option><option value='Seo'>Seo</option><option value='Link Exchanger'>Link Exchanger</option><option value='Content writer'>Content writer</option><option value='Blog writer'>Blog writer</option>");
out.print("<option value='Project Leader'>Project Leader</option><option value='Client Manager'>Client Manager</option><option value='Network trainee'>Network trainee</option><option value='Network Administrator'>Network Administrator</option>");
out.print("<option value='Network Maintenance'>Network Maintenance</option><option value='Site Pramoter'>Site Pramoter</option><option value='Peon'>Peon</option><option value='Accountant'>Accountant</option><option value='Lab incharge'>Lab incharge</option>");
out.print("<option value='Senior Soft Engg'>Senior Soft Engg</option><option value='Market Excecutive'>Market Excecutive</option><option value='Telly Caller '>Telly Caller </option><option value='Assistend Dba'>Assistend Dba</option><option value='Dba'> Dba</option>");
out.print("<option value='Script Writer'>Script Writer</option><option value='Html Programmer'>Html Programmer</option><option value='XML Programmer'>XML Programmer</option><option value='Java Developer'>Java Developer</option><option value='.Net Developer'>.Net Developer</option>");
out.print("<option value='Jsp Programmer'>Jsp Programmer</option><option value='Asp Programmer'>Asp Programmer</option><option selected>Select One</option></select></td></tr>");
out.print("<tr><td>Date of Joining </td><td>"+date_of_join+"</td><td><input name='dateofjoin1' type='text' size='10' maxlength='10' > dd/mm/yyyy formet </td></tr>");
out.print("<tr><td>Salary </td><td>"+salary+"</td><td> <input name='salary1' type='text' size='12' maxlength='12' >in Rs.</td></tr>");
out.print("<tr><td>Mobile No.</td><td>"+mobile_no+"</td><td><input name='mobile1' type='text' size='15' maxlength='10' >without country code</td></tr>");
out.print("<tr><td>Name </td><td>"+Name+"</td><td><input name='name' type='text' size='25' maxlength='49'> </td></tr>");
out.print("<tr><td>Gender </td><td>"+Gender+"</td><td> <select name='gender1' size='1' ><option selected>Choose one</option><option value='Male' >Male</option><option value='Female'>Female</option></select></td></tr>");
out.print("<tr><td>Address </td><td>"+Address+"</td><td> <input name='address1' type='text' size='25' maxlength='49' > </td></tr>");
out.print("<tr><td>Last Modified By </td><td>"+edited_by+"</td><td>Software Generated Field </td></tr>");
out.print("<tr><td>Last Modification Date </td><td>"+date_of_modification+"</td><td> Software Generated FIeld</td></tr></table>");
out.print("</b><div align='center'><input type='Submit' name='update' value='Update Record'> <input type='Reset' name='Reset' value='Reset Information'>");
out.print("</form>");
}
else
out.println("<b>Sorry for Inconvenience There is Some Problem With the server To Accessing the Database,So Error in the Record Updation.</b>");
}//end of try
catch(Exception e)
{
out.print(e);
}//end of catch
}//end of else if
else
{
out.print("Sorry Dear Either You Lost your Session For You Trying To Make Fool The Server.you are not an Authorized User To View This Page.<br>Your Ip Address "+request.getRemoteHost()+"Is Logged");
}
%>


</body>
</html>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calling a java Script file into the Jsp