pradweepkishwar
pradweepkishwar

Reputation: 1

getting 404 status error while executing servlet program using tomcat7.0.30

import java.io.*;  
import java.util.*;  
import javax.servlet.*;  
import javax.servlet.http.*;  

public class One extends HttpServlet  
{  
public void doGet(HttpServletRequest request,HttpServletResponse response)throws    IOException,ServletException  
{  
response.setContentType("text/html");  
PrintWriter pw= response.getWriter();  
pw.println("helloooo ORANGE");  
}  
}  

<web-app>  
<servlet>  
<servlet-name>mango</servlet-name>  
<servlet-class>One</servlet-class>  
</servlet>  

<servlet-mapping>  
<servlet-name>mango</servlet-name>    
<url-pattern>/mango</url-pattern>  
</servlet-mapping>  
</web-app>       

I am using tomcat 7.0.30 and I had an error i.e 404 status error, if I am not importing util package, please tell me what is the need of importing of util package since we are not using it.

Upvotes: 0

Views: 877

Answers (1)

Martin Wilson
Martin Wilson

Reputation: 3386

I think you are asking two questions.

I'll answer the second question first ("what is the need of importing of util package since we are not using it"): there is no need. You can remove this import statement.

Re the second question (why you are getting a 404): try flushing and closing (which probably flushes it anyway) the PrintWriter as this will commit the response. For example:

pw.flush();
pw.close();

This is worth a try, although I think Tomcat ought to do this for you.

Upvotes: 1

Related Questions