-
Is it possible to use java script in servlets? (7 messages)
- Posted by: Priyanka Shah
- Posted on: August 06 2002 13:41 EDT
I wanted to use javascript that is sent to client browser for client side validation from the servlet. I am not sure if the javascript works with servlets. I commented all the javascript except for the script tag and it still says "object not found" when I submit the form.. Am I supposed to include something? Please help
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Login extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException
{
PrintWriter pw = response.getWriter();
response.setContentType("text/html");
pw.println("<html><head>"+
"<script language=\"text/javascript\">"+
//"function validate()"+
//"{"+
//"x=document.LoginForm"+
//"pass=x.txt_password.value"+
//"submitOK=\"True\""+
//"if (pass.length>6)"+
//"{"+
//"alert(\"Your password must be 6 characters or less\")"+
//"submitOK=\"False\""+
//"}"+
//"if (submitOK==\"False\")"+
//"{"+
//"return false"+
//"}"+
//"}"+
"</script></head>"+
"<body bgcolor =\"FFFFFF\">"+
"<form name=\"LoginForm\" method=\"POST\" action=\"LoginCheck\" onsubmit=\"return validate()\">
<b>Enter ID<input type=\"password\" value=\"\" name=\"txt_username\">
<b>Enter PIN</b><input type=\"password\" name=\"txt_password\" size=\"20\">
<input type=\"submit\" value=\"Login\" name=\"bttn_logincheck\"></td></tr></table></center>"+
"</form></body></html>");
}//doPost
}//main servletThreaded Messages (7)
- Is it possible to use java script in servlets? by Shawn Conner on August 06 2002 14:44 EDT
- Is it possible to use java script in servlets? by Priyanka Shah on August 07 2002 09:52 EDT
- Is it possible to use java script in servlets? by Shawn Conner on August 06 2002 14:44 EDT
- Is it possible to use java script in servlets? by Manoj Joseph on August 07 2002 05:45 EDT
- Is it possible to use java script in servlets? by Atit Patel on August 07 2002 09:12 EDT
- confusion by fff fff on October 11 2011 09:10 EDT
-
Is it possible to use java script in servlets?[ Go to top ]
- Posted by: Shawn Conner
- Posted on: August 06 2002 14:44 EDT
- in response to Priyanka Shah
You can use JavaScript in Servlets. The reason I believe that you are getting the object not found error is that you are calling the validate function, but it is commented out in your code. -
Is it possible to use java script in servlets?[ Go to top ]
- Posted by: Priyanka Shah
- Posted on: August 07 2002 09:52 EDT
- in response to Shawn Conner
Thank you very much. I was not using semicolons at the end to end the statement. This works with html on a browser. When it coming from a servlet it doesnt and semicolons are required when ending statements.
-
check it[ Go to top ]
- Posted by: fff fff
- Posted on: October 11 2011 09:30 EDT
- in response to Priyanka Shah
out.println("<html><head>"+"<script type=\"text/javascript\">"+"document.write(\"click on this button\");"+"var str"+"function cc()"+"{"+ "str=prompt(\"enter your name:\")"+ "alert(str+\"is MAD!\")"+"}"+"</script>"+"</head>"+"<body>"+"<input type='button' value='click me money' onclick='cc()'>"+"</body>"+"</html>");
-
Is it possible to use java script in servlets?[ Go to top ]
- Posted by: Shawn Conner
- Posted on: August 06 2002 14:44 EDT
- in response to Priyanka Shah
You can use JavaScript in Servlets. The reason I believe that you are getting the object not found error is that you are calling the validate function, but it is commented out in your code. -
Is it possible to use java script in servlets?[ Go to top ]
- Posted by: Manoj Joseph
- Posted on: August 07 2002 05:45 EDT
- in response to Shawn Conner
Yes it is possible to use Java Script with servlets.
When you get into client side problems like this,
1. save a copy of the page that you see in your browser
2. debug it
3. make sure your servlet generates the debugged version.
Regards,
Manoj -
Is it possible to use java script in servlets?[ Go to top ]
- Posted by: Atit Patel
- Posted on: August 07 2002 09:12 EDT
- in response to Priyanka Shah
Hi,
Ya, its possible and i think better way is to use netscape scripti API. Just try to download that api. And by using the functions of that API, u can easily manupulate with scripts. I don't exactly remember the URL for download the api, but i'll give it to u ASAP.
Thanks,
Atit. -
confusion[ Go to top ]
- Posted by: fff fff
- Posted on: October 11 2011 09:10 EDT
- in response to Priyanka Shah
y u used "//" in betwwen the code..? these are used for commenting purposes... will it work as u hav made it comments