• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

i want to insert my javascript coding with my servlets program help me

 
shamganth
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Twoservletmethods extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
PrintWriter pw=res.getWriter();
pw.println("<html>");
pw.println("javascript");
pw.println("<Script>");
pw.println(" alert("hello")");
pw.println(" </Script>");
pw.println("</html>");
pw.close();
}
}
this is my coding but i will not able to compile this would any one help me to suceed in this.
ur advice and suggestions are most welcome,
thank u,
k.shamganth
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Ranch has a naming policy, described here and "shamganth" is not a valid name. Please choose one which meets the requirements.
Thanks.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code looks OK on a cursory examination, but most "can't compile servlet" problems are actually realted to what you have (or don't have) in your classpath.
What is the error you are getting when you try to compile this?
 
Malu Sivasankar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Change pw.println(" alert("hello")");
to pw.println(" alert(\"hello\")");
Code will compile....
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D'Oh! I should have spotted that. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic