• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Head First JSP Book Ch1 Example

 
Roger Studner
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic