Javascript $document.ready()在servlet内不工作
我在Javascript $document.ready()在servlet内不工作,javascript,jquery,css,jsp,servlets,Javascript,Jquery,Css,Jsp,Servlets,我在Javaservlet中使用javascript和html。我使用get方法将参数从jsp页面传递到servlet,因此在servlet中使用doGet方法。 该行: out.println("$(document).ready(function{alert('Inside a function')});"); //is not working. 如果我删除此语句,代码将正常运行,即它会向1和2发出警报 protected void doGet(HttpServletRequest re
Javaservlet
中使用javascript和html。我使用get方法将参数从jsp页面传递到servlet,因此在servlet中使用doGet方法。
该行:
out.println("$(document).ready(function{alert('Inside a function')});"); //is not working.
如果我删除此语句,代码将正常运行,即它会向1和2发出警报
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
out.println("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>");
out.println("<head>"+"<link href='./styles/styles.css' type= 'text/css' rel='stylesheet'/>");
out.println("<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js' type='text/javascript'></script>");
out.println("<script src='http://jquery-star-rating-plugin.googlecode.com/svn/trunk/jquery.rating.js' type='text/javascript' language='javascript'></script>");
out.println("<link href='http://jquery-star-rating-plugin.googlecode.com/svn/trunk/jquery.rating.css' type='text/css' rel='stylesheet'/>");
out.println("<script type='text/javascript' language='javascript'>");
out.println("alert('1');"); out.println("$(document).ready(function{alert('Inside a function')});"); out.println("alert('2');");
out.println("</script>"); //closing the script tag
out.println("</body>"); //closing the body tag
out.println("</html>"); //closing the html tag
out.close();
}
protectedvoiddoget(HttpServletRequest),
HttpServletResponse响应)引发ServletException,IOException{
response.setContentType(“text/html”);
PrintWriter out=response.getWriter();
out.println(“”);
out.println(“”);
out.println(“+”);
out.println(“”);
out.println(“”);
out.println(“”);
out.println(“”);
out.println(“警报('1');”);out.println($(document).ready(函数{alert('Inside a function')));”);out.println(“警报('2');”);
out.println(“”;//关闭脚本标记
out.println(“”;//关闭body标记
out.println(“”;//关闭html标记
out.close();
}
试试这个:
$(document).ready(function(){alert('Inside a function')});
$(document).ready(函数{alert('函数内部'))})代码>不是有效的JavaScript