import java.io.*;
import javax.servlet.*;
import javax.servlet.httpservlet.*;
public class FirstServlet extends HttpServlet{

public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException{

res.setContentType("text/html");
PrintWriter out=res.getWriter();


res.sendRedirect("/FirstServlet/index.html");

}

}//end of get



public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException{

res.setContentType("text/html");
PrintWriter out=res.getWriter();

String name= req.getParameter("name");
if(name.equals("")){
res.sendRedirect("/FirstServlet/ContacUs.html");
}else{
requestDispatcher rd= req.getRequestDispatcher("/second");
rd.forward(req,res);
}

}//end of post

}

-----

C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\FirstServletTrial
\WEB-INF\src>javac -d . *.java
FirstServlet.java:19: error: class, interface, or enum expected
public void doPost(HttpServletRequest req, HttpServletResponse res)throws Servle
tException,IOException{
       ^
FirstServlet.java:22: error: class, interface, or enum expected
PrintWriter out=res.getWriter();
^
FirstServlet.java:24: error: class, interface, or enum expected
String name= req.getParameter("name");
^
FirstServlet.java:25: error: class, interface, or enum expected
if(name.equals("")){
^
FirstServlet.java:27: error: class, interface, or enum expected
}else{
^
FirstServlet.java:29: error: class, interface, or enum expected
rd.forward(req,res);
^
FirstServlet.java:30: error: class, interface, or enum expected
}
^
7 errors

Recommended Answers

All 2 Replies

you have two closing brackets on your doGet method.
remove the second one, and you'll have less errors. I haven't checked every single bracket pair to see if there are some other places where you have missing/extra brackets, but if you indent your code, and re-check it, if need be with help of the stack trace, you'll work yourself out of it in a matter of seconds.

also: for questions concerning jsp and servlets, this forum is more suited to post in.

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.