how to point my jsp form action to servlet?

how to point my jsp form action to servlet?

I am currently using netbean 6.8, tomcat 6.0, and mysql database.
I was having problem when I was trying to point my jsp action to my servlet.(f.action="../fyp.servletLogin";) fyp is the folder that stores my servlet.
Here is my function code in jsp, when user click on submit button, it will calls this login function to pass value to servlet.

function login() {
var f = document.index;
var length;
var userID = f.UserID.value;
var userPwd = f.UserPwd.value;

length = userID.length;
if (length < 1) {
alert("User ID is null. Please key in User ID.");
f.UserID.focus();
return(false);
}

length = userPwd.length;
if (length < 1) {
alert("Password is null. Please key in Password.");
f.UserPwd.focus();
return(false);
}
alert(userPwd.valueOf());
alert(userID.valueOf());
f.method = "POST";
f.action = "../fyp.servletLogin";
f.submit();
}
View Answers

April 15, 2010 at 12:36 PM

Hi Friend,

Try the following code:

1)login.jsp:

<script>
function login() {
var f = document.form;
var length;
var userID = f.UserID.value;
var userPwd = f.UserPwd.value;

length = userID.length;
if (length < 1) {
alert("User ID is null. Please key in User ID.");
f.UserID.focus();
return(false);
}

length = userPwd.length;
if (length < 1) {
alert("Password is null. Please key in Password.");
f.UserPwd.focus();
return(false);
}
//alert(userPwd.valueOf());
//alert(userID.valueOf());
f.method = "POST";
f.action = "../servletLogin?user="+userID+"&&pass="+userPwd;
f.submit();
}
</script>
<form name="form">
<table>
<tr><td>Username</td><td><input type="text" name="UserID"></td></tr>
<tr><td>Password</td><td><input type="text" name="UserPwd"></td></tr>
<tr><td><input type="button" value="Submit" onclick="return login();"></td></tr>
</table>
</form>

2)servletLogin.java

import javax.servlet.http.*;

public class servletLogin extends HttpServlet {

public void doPost (HttpServletRequest request,HttpServletResponse response) {
String username=request.getParameter("user");
String password=request.getParameter("pass");

}
}

Thanks









Related Tutorials/Questions & Answers:
how to point my jsp form action to servlet? - JSP-Servlet
How to validate a form in action class and forward errors to the jsp in struts?
Advertisements
how to display action errors in jsp which is in a form list
how do i provide down a pdf document fecility on my web page using jsp and servlets?
servlet7
servlet3
servlet4
servlet5
servlet2
Capturing JSP Content Within My Strut Action Servlet - JSP-Servlet
how to execute jsp and servlets with eclipse
what is wrong with my JSP codes for updating a form?
servlet6
servlet6
linking tree heading in javasript into a Jsp file and then jsp to struts action form
how to execute jsp and servlets with eclipse
Action form
how to display output on jsp from while loop of action class....actually i am retreiving the post from posts column from my sql.plz help.thnkss
jsp -servlets
how to update values of a html form into an excel table using java servlets?
How can i pass the valus from a JSP to the action class???
Action without a form.
How to validate a form - JSP-Servlet
servlet1
servlet1
servlet1
servlet1
servlet1
servlet1
servlet1
servlet1
servlet1
servlet1
Jsp Action Tags
how to use one form out of multiple form from one jsp to another jsp
Servlets in JSF - JSP-Servlet
RADIO FROM JSP TO ACTION.
how to write a jsp form using html
How to Upload a file directly to Oracle database using JSP or Servlets?
jsp form
Action tag - JSP-Servlet
jsp and servlets
How to export web page to excel using java or jsp or servlets
JSP Forward action
How to pass Array of string from action class to jsp page
how to include Timestamp into my enquiry form? - Java Beginners
how to get a values from a multipart/form-data - JSP-Servlet
JSP-Servlets-JDBC
jsp form
Servlets,Jsp,Javascript - JSP-Servlet

Ads