Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 21st, 2006, 12:54 AM   #1
hemanth.balaji
Programmer
 
Join Date: May 2005
Posts: 54
Rep Power: 0 hemanth.balaji is an unknown quantity at this point
Send a message via Yahoo to hemanth.balaji Send a message via Skype™ to hemanth.balaji
HTTP Status 405 - HTTP method POST is not supported by this URL

I am using Apache Tomcat

I got the following error when invoking a jsp.

type Status report

message HTTP method POST is not supported by this URL

description The specified HTTP method is not allowed for the requested resource (HTTP method POST is not supported by this URL).

My 2 files are

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

public class LoginServlet1 extends HttpServlet {

private void sendLoginForm(HttpServletResponse response,
boolean withErrorMessage)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Login</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");

if (withErrorMessage)
out.println("Login failed. Please try again.<BR>");

out.println("<BR>");
out.println("<BR>Please enter your user name and password.");
out.println("<BR><FORM METHOD=POST>");
out.println("<BR>User Name: <INPUT TYPE=TEXT NAME=userName>");
out.println("<BR>Password: <INPUT TYPE=PASSWORD NAME=password>");
out.println("<BR><INPUT TYPE=SUBMIT VALUE=Submit>");
out.println("</FORM>");
out.println("</BODY>");
out.println("</HTML>");

}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
sendLoginForm(response, false);
}

public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String userName = request.getParameter("userName");
String password = request.getParameter("password");
if (userName!=null && password!=null &&
userName.equals("hemanth") && password.equals("balaji")) {
RequestDispatcher rd = request.getRequestDispatcher("WelcomeServlet");
rd.forward(request, response);
}
else {
sendLoginForm(response, true);
}

}
}


and,

WelcomeServlet.java

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

public class WelcomeServlet extends HttpServlet {

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Hi from Servlet Demo</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("Welcome to the Servlet Demo");
out.println("</BODY>");
out.println("</HTML>");
}
}


Thanks and regards,
Hemanth
http://www.freejavaguide.com
hemanth.balaji is offline   Reply With Quote
Old Mar 21st, 2006, 1:37 AM   #2
Nebula
Hobbyist Programmer
 
Nebula's Avatar
 
Join Date: Oct 2005
Posts: 198
Rep Power: 3 Nebula is on a distinguished road
Send a message via AIM to Nebula
LoginServlet1
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class LoginServlet1 extends HttpServlet {

private void sendLoginForm(HttpServletResponse response,
boolean withErrorMessage)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Login</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");

if (withErrorMessage)
out.println("Login failed. Please try again.<BR>");

out.println("<BR>");
out.println("<BR>Please enter your user name and password.");
out.println("<BR><FORM METHOD=POST>");
out.println("<BR>User Name: <INPUT TYPE=TEXT NAME=userName>");
out.println("<BR>Password: <INPUT TYPE=PASSWORD NAME=password>");
out.println("<BR><INPUT TYPE=SUBMIT VALUE=Submit>");
out.println("</FORM>");
out.println("</BODY>");
out.println("</HTML>");

}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
sendLoginForm(response, false);
}

public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String userName = request.getParameter("userName");
String password = request.getParameter("password");
if (userName!=null && password!=null &&
userName.equals("hemanth") && password.equals("balaji")) {
RequestDispatcher rd = request.getRequestDispatcher("WelcomeServlet");
rd.forward(request, response);
}
else {
sendLoginForm(response, true);
}

}
}


and,

WelcomeServlet.java

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

public class WelcomeServlet extends HttpServlet {

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Hi from Servlet Demo</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("Welcome to the Servlet Demo");
out.println("</BODY>");
out.println("</HTML>");
}
}

Alot easier to read your code if you use the code bars.
__________________
When will Jesus bring the porkchops?
Nebula is offline   Reply With Quote
Old Mar 21st, 2006, 1:42 AM   #3
hemanth.balaji
Programmer
 
Join Date: May 2005
Posts: 54
Rep Power: 0 hemanth.balaji is an unknown quantity at this point
Send a message via Yahoo to hemanth.balaji Send a message via Skype™ to hemanth.balaji
Hi i see no change in the code.
hemanth.balaji is offline   Reply With Quote
Old Mar 21st, 2006, 1:46 AM   #4
Nebula
Hobbyist Programmer
 
Nebula's Avatar
 
Join Date: Oct 2005
Posts: 198
Rep Power: 3 Nebula is on a distinguished road
Send a message via AIM to Nebula
I never said nor implied that their was a change in the code but it is ALOT easier to read and understand their for getting a better reply.
__________________
When will Jesus bring the porkchops?
Nebula is offline   Reply With Quote
Old Mar 21st, 2006, 2:35 AM   #5
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
Quote:
Originally Posted by Nebula
I never said nor implied that their was a change in the code but it is ALOT easier to read and understand their for getting a better reply.
Not really, the main point about the code tags is to preserve indenting, so that you can line up all those ifs and whiles.
The Dark is offline   Reply With Quote
Old Mar 21st, 2006, 2:48 AM   #6
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
Maybe it is the "WelcomeServlet" page that can't handle POSTs. Maybe you could try doing something simple when you get the original POST, say just returning back some simple html.
The Dark is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:35 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC