This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JSP and the fly likes Head First JSP Book Ch1 Example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Head First JSP Book Ch1 Example" Watch "Head First JSP Book Ch1 Example" New topic
Author

Head First JSP Book Ch1 Example

Roger Studner
Greenhorn

Joined: Aug 26, 2005
Posts: 6
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.Date;

public class Ch1Servlet extends HttpServlet {

public void doGet(HttpServlet request,
HttpServletResponse response)
throws IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Date today = new Date();
out.println("<html>" +
"<body>" +
"<h1 align=center>First Try.</h1>" +
"<br>" + today + "</body>" + "</html>");

}
}

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLScheme-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Chapter1 Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>
</web-app>

All directory structures are 100% correct

Result:

HTTP Status 405 - HTTP method GET is not supported by this URL

type Status report

message HTTP method GET is not supported by this URL

description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).
Apache Tomcat/5.5.9

Any help?
Roger Studner
Greenhorn

Joined: Aug 26, 2005
Posts: 6
i changed the XMLScheme-instance to XMLSchema-instance (typo).. but that had no effect.

Also.. I noted in a pile of other web.xml's it is xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" (the head start book has no / between j2ee and web-app_2_4.xsd"

that being said.. no effect, ntohing works.

oh the joy, example 1 in a book with tons.. with no luck hahaha.. demotivating.

and I added (after it not working anyway) the response.setType only because all the apache/tomcat examples do that.

[ August 29, 2005: Message edited by: Roger Studner ]
[ August 29, 2005: Message edited by: Roger Studner ]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Roger Studner:



See the code carefully. You need to change the first argument of you r doGet() method.

make it like below,

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{. . . .. }
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First JSP Book Ch1 Example
 
Similar Threads
Tomcat problem
404 Error
new to tomcat
Servlet is not running
really simple servlets,but why second one not work