S
sangeeta chowdhary
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.
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.