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
Capturing JSP Content Within My Strut Action Servlet - JSP-Servlet
servlet2
what is wrong with my JSP codes for updating a form?
linking tree heading in javasript into a Jsp file and then jsp to struts action form
how to execute jsp and servlets with eclipse
servlet6
servlet6
Action form
how to execute jsp and servlets with eclipse
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
Action without a form.
How can i pass the valus from a JSP to the action class???
how to update values of a html form into an excel table using java servlets?
Jsp Action Tags
servlet1
servlet1
servlet1
servlet1
servlet1
servlet1
servlet1
servlet1
servlet1
servlet1
How to validate a form - JSP-Servlet
Servlets in JSF - JSP-Servlet
RADIO FROM JSP TO ACTION.
how to use one form out of multiple form from one jsp to another jsp
jsp form
Action tag - JSP-Servlet
jsp and servlets
JSP Forward action
how to write a jsp form using html
How to Upload a file directly to Oracle database using JSP or Servlets?
JSP-Servlets-JDBC
jsp form
Servlets,Jsp,Javascript - JSP-Servlet
How to export web page to excel using java or jsp or servlets
How to pass Array of string from action class to jsp page
jsp and servlets
Search page form in jsp

Ads