From: sangeeta chowdhary on
hi,
I have written a servlet

import music.business.User;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import music.data.*;

public class RegisterUserServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException,

ServletException {
doPost(request, response);
}

public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
HttpSession session = request.getSession();

String firstName = request.getParameter("firstName");
String lastName = request.getParameter("lastName");
String emailAddress = request.getParameter("emailAddress");

User user = new User();
user.setFirstName(firstName);
user.setLastName(lastName);
user.setEmailAddress(emailAddress);
try
{
if (UserDB.emailExists(emailAddress))
UserDB.update(user);
else
UserDB.insert(user);
} catch(Exception e) {}
session.setAttribute("user", user);

Cookie emailCookie = new Cookie("emailCookie", emailAddress);
emailCookie.setMaxAge(60*60*24*365*2);
emailCookie.setPath("/");
response.addCookie(emailCookie);

String url = "/catalog/writeDownload";
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
}

}


my jsp code is calling this servlet


<jsp:include page="/includes/header.html" />
<jsp:include page="/includes/column_left_all.jsp" />

<!-- start the middle column -->

<td>

<script language="JavaScript">
function validate(form) {
if (form.firstName.value=="") {
alert("Please fill in your first name");
form.firstName.focus();
}
else if (form.lastName.value=="") {
alert("Please fill in your last name");
form.lastName.focus();
}
else if (form.emailAddress.value=="") {
alert("Please fill in your email address");
form.emailAddress.focus();
}
else {
form.submit();
}
}
</script>

<h1>Download registration</h1>

<p>Before you can download and listen to these sound files,
you must register with us by entering your name and email
address below.</p>

<!-- Import the core JSTL library -->
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!-- Use the JSTL url tag to encode the URL -->
<form action="<c:url value='/catalog/registerUser'/>"
method="post">
<table cellpadding="5" border="0">
<tr>
<td align="right"><p>First name:</td>
<td><input type="text" name="firstName"></td>
</tr>
<tr>
<td align="right"><p>Last name:</td>
<td><input type="text" name="lastName"></td>
</tr>
<tr>
<td align="right"><p>Email address:</td>
<td><input type="text" name="emailAddress"></td>
</tr>
<tr>
<td></td>
<td><input type="button" value="Submit"
onClick="validate(this.form)"></td>
</tr>
</table>
</form>

</td>

<!-- end the middle column -->

<jsp:include page="/includes/column_right_buttons.jsp" />
<jsp:include page="/includes/footer.jsp" />


when i run my servlet,browser display this message-

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

i have given proper url to this servlet through web.xml also.

kindly help me to provide solution for this problem.
Thank you.

From: Lew on
sangeeta chowdhary wrote:
> I have written a servlet
> ...
>         <td><input type="button" value="Submit"
>                    onClick="validate(this.form)"></td>
>       </tr>
>     </table>
>   </form>
> ...
> when i [sic] run my servlet,browser display this message-
>
> HTTP Status 405 - HTTP method GET is not supported by this URL
>
> i [sic] have given proper url to this servlet through web.xml also.
>

What happens if you eliminate the 'onClick' from the input button?

Also, I am pretty sure you should not use "<c:url>" in the form
'action' attribute, but just the servlet reference:

<form action="/catalog/registerUser" method="post">

I realize you're trying to prevent issues if cookies are disabled, but
I don't think that consideration applies to the 'action' attribute.
You can tell that I'm not certain about this, so try it and report
what happens.

There are several petty issues with your code as well, not relevant to
your question nor likely to cause you serious trouble in this
particular case, but they represent bad habits such as failure to
enclose 'if' clauses in curly braces.

Really good example you posted, btw. Nicely complete.

--
Lew
From: sangeeta chowdhary on
On Apr 13, 10:43 pm, Lew <l...(a)lewscanon.com> wrote:
> sangeeta chowdhary wrote:
> > I have written a servlet
> > ...
> >         <td><input type="button" value="Submit"
> >                    onClick="validate(this.form)"></td>
> >       </tr>
> >     </table>
> >   </form>
> > ...
> > when i [sic] run my servlet,browser display this message-
>
> > HTTP Status 405 - HTTP method GET is not supported by this URL
>
> > i [sic] have given proper url to this servlet through web.xml also.
>
> What happens if you eliminate the 'onClick' from the input button?
>
> Also, I am pretty sure you should not use "<c:url>" in the form
> 'action' attribute, but just the servlet reference:
>
>  <form action="/catalog/registerUser" method="post">
>
> I realize you're trying to prevent issues if cookies are disabled, but
> I don't think that consideration applies to the 'action' attribute.
> You can tell that I'm not certain about this, so try it and report
> what happens.
>
> There are several petty issues with your code as well, not relevant to
> your question nor likely to cause you serious trouble in this
> particular case, but they represent bad habits such as failure to
> enclose 'if' clauses in curly braces.
>
> Really good example you posted, btw.  Nicely complete.
>
> --
> Lew

Thanks for your reply sir.
I have tried using -
<form action="/catalog/registerUser" method="post">

but it is still not working.
If i remove onClick button then it will not validate the form.
From: Lew on
sangeeta chowdhary quoted the sig:
>> --
>> Lew

Please do not quote sigs.

Lew wrote:
>> What happens if you eliminate the 'onClick' from the input button?
>

sangeeta chowdhary wrote:
> If i [sic] remove onClick button then it will not validate the form.

Not on the client side, no, it won't, but that doesn't matter a whit.
Sometimes when you are diagnosing the problem you have to try things
that you know won't stay in the final version, but are necessary to
understand the situation.

I ask again, what happens if you eliminate the 'onClick' from the
input button? I mean, with respect to the bug you're hunting, of
course. I wonder (because I do not know) if somehow the JS is forcing
a GET instead of a POST. OTOH, you handle GET, so I'm mystified.

I really don't see in your code how that error 405 can happen, so I'm
taking shots in the dark.

--
Lew
From: John B. Matthews on
In article
<a0c92b45-c9b8-435f-82b1-e387df8982e5(a)b23g2000yqn.googlegroups.com>,
Lew <lew(a)lewscanon.com> wrote:

> sangeeta chowdhary quoted the sig:
> >> --
> >> Lew
>
> Please do not quote sigs.
>
> Lew wrote:
> >> What happens if you eliminate the 'onClick' from the input button?
> >
>
> sangeeta chowdhary wrote:
> > If i [sic] remove onClick button then it will not validate the form.
>
> Not on the client side, no, it won't, but that doesn't matter a whit.
> Sometimes when you are diagnosing the problem you have to try things
> that you know won't stay in the final version, but are necessary to
> understand the situation.
>
> I ask again, what happens if you eliminate the 'onClick' from the
> input button? I mean, with respect to the bug you're hunting, of
> course. I wonder (because I do not know) if somehow the JS is
> forcing a GET instead of a POST. OTOH, you handle GET, so I'm
> mystified.

If doGet() was a late addition, I'd wonder if the servlet container
needs to be restarted or the context reloaded. Using Tomcat, I've become
accustomed to the convenience of Manager App:

<http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html>

> I really don't see in your code how that error 405 can happen, so I'm
> taking shots in the dark.

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
 |  Next  |  Last
Pages: 1 2 3
Prev: file loading
Next: Free Online Subversion Training