Validate username as input is provided to textbox in jsp - mysql

I have a jsp form in which a user can signup by entering username and password. I have to check dynamically whether the username exists in mysql database as the username is typed into the text box. Here is a sample code:
<html>
<head>Sample Signup</head>
<body>
<form action="updatedb.jsp" method="post">
Username : <input type="text" name="uname">
<br>
Password : <input type="text" name="upass">
<br>
<input type="submit" value="signup">
</form>
</body>
</html>
I am new to jsp so an elaborated answer will be more helpful. If i missed any other important info, ask me right away.

Java cannot respond to the client-side methods like onChange (not directly). Those methods call Javascript. Javascript is not actually related in any way to Java; its only called that because it uses the bracket-style syntax for functions as opposed to VB-style syntax. The only way to involve Java itself in the client-side methods would be to use Javascript to send an Ajax request to a JSP/Servlet and receive a response back. The simplest way to send an Ajax request in Javascript is with jquery (a javascript library).

Related

How can I find a website's login form URL variables?

I am trying to make a code that will automatically login into a webpage for you, but I am having trouble finding the url variables for the submission.
How can I find the url variables to submit the login?
i.e.
https://login.fidelity.com/ftgw/Fas/Fidelity/RtlCust/Login/Init
When I submit my username and password on the site, it passes it through to
https://login.fidelity.com/ftgw/Fas/Fidelity/RtlCust/Login/Response
The username <input> has id="userId", and the password <input> has id="password", and this is all under a <form> which has method="POST"
How can I find all variables that I need to submit?
The URL variables aren't always in the URL.
Most Login forms use a method of transferring that data called "POST".
In which the URL data cannot be seen by the user.
You can try using http://www.wireshark.org/ or http://www.charlesproxy.com/ to view the data sent and received by your web browser.
To find the name of the URL parameters (such as ?username=....&pas=...).
You can look into the HTML of the page. Look for something like so:
<form action="login.php" method="post">
<input type="text" name="username" value="User Types Username Here">
<input type="submit">
</form>
Can use Chrome (Ctrl + Shift + J) Network tools. Click "Preserve Log" to ensure you capture payload before page refreshes.

Beginner in html and objective-c, nsurlconnection and html values

I'm currently working with objective-c and have run in to a problem concerning javascript. I am connecting to a website through an iphone app and my goal is to login to a html form (Login.jsp)
<label class="login_label">Username</label>
<input autocomplete="off" type="text" value="" name="ssusername" size="20" maxlength="50" />
<label class="login_label">Password</label>
<input autocomplete="off" type="password" name="sspassword" size="20" maxlength="20" value=""/>
I am trying to make a NSUrlConnection to this site in objective-c but the concern is this: If I enter
https://www.login.com/Login.jsp?ssusername=%#&sspassword=%#, username.text, password.text
It will only enter the enter the password in the html form. And when I look at the javascript I suspect it has something to do with the value in the username html code being value=""
My question: Is it possible to, without changing the html code (as I don't have access to it) make a NSUrlConnection passing username and password and retrieving the answer from this html form, or if anyone know why the username wont show when the adress is entered as above?
I think, login method may use POST method and your NSURLConnection is using get method.
You can check at POST with NSURLConnection - NO JSON.
It depends on server side. You can't really change input field value via GET parameters -- it's server-side job.
You can execute JS code to enter username and password and then click login button via UIWebView's stringByEvaluatingJavaScriptFromString function or you can check this site/server documentation for some authentication methods and then use them (like #saturngod suggested).

How do I make a simple email form submission in HTML?

I tried w3schools but it didn't help and I tried other websites too. I just wanna make a short html script that sends an email to an email address, but I keep reloading my email inbox and nothing comes up. Can you help?
<form action="MAILTO:MY_EMAIL#yahoo.com" method="post" enctype="text/plain">
<input type="text" name="email" value="Email">
<input type="text" name="message" value="Message">
<input value="Submit" type="submit">
</form>
You need to use a server side script here. HTML alone won't help you here. HTML is just the frontend logic. You need some script on backend that accepts this data you submit and actually sends out an email. To take the example in PHP, assuming u have the server set up and all or that your shared
<form action="sendmail.php" method="post" enctype="text/plain">
<input type="text" name="email" value="Email">
<input type="text" name="message" value="Message">
<input value="Submit" type="submit">
</form>
sendmail.php
$email=$_POST['email'];
$message=json_encode($_POST);
$receiver="MY_EMAIL#yahoo.com";
$mailer="mailer#myservice.com";
mail($email,"Message for enquiry or whatever",$message, array("from"=>$mailer));
There were, at some point, browsers that supported forms of this type. However, they're all gone now -- you will need a server-side script to send email. It's impossible to do using HTML alone.
You are confusing a few things.
When you Submit a form, it goes from the client (browser) to your server, which acts upon it. The form action needs to be a URL which handles the request. The mailto: URI scheme is not a valid action to use.
You have two choices:
You can create a mailto: link like this:
Send email
which will open your default email client,
OR
You can put a URL corresponding to an end point on your server, something like
form action="/send/mail"...
and have your server send the email
I believe the easiest way to do this is using a service like Zapier or IFTTT. Both of them offer a way to create Zaps/Applets that can send an email when you post to a specific url.
This is what configuration would look like in IFTTT and Zapier .
IFTTT is simpler to setup, Zapier has more options, like sending to more than one emails. I believe IFTTT only lets you send to your account's email.

Capture POST response in HTML page

I am sending a form post to a third party and it is returning a page with Success if the action is done. Once I get the success page, I need to redirect user to a Thank You page. Can somebody tell me how the see if the success page is returned and redirect to another page?
<form name="abc" method="POST" action="third party url" >
<input />
<input />
</form>
... how about submitting the form and receiving response in an iframe? If you can use an iframe you'll be able to detect the change then.
the code goes like this:
<form name="abc" method="POST" action="third party url" >
<input/>
<input/>
</form>
but i am not sure how to capture the response
You won't be able to do this easily with plain javascript. When you post a form, the form inputs are sent to the server and your page is refreshed - the data is handled on the server side. That is, the submit() function doesn't actually return anything, it just sends the form data to the server.
If you really wanted to get the response in Javascript (without the page refreshing), then you'll need to use AJAX, and when you start talking about using AJAX, you'll need to use a library. jQuery is by far the most popular, and my personal favourite. There's a great plugin for jQuery called Form which will do exactly what it sounds like you want.

How to use the form value in the action?

I am trying to make a form in html that uses the value you enter to form the destination URL.
<form action="../search/${params.q}" method="post" id="q">
Busqueda: <input type="text" name="q" /><br />
</form>
This is what i am doing, but it does not work, any cluess? thanks!
You'd need to handle this using a script - either server-side or on the client (JavaScript).
HTML alone can't handle parameters in the way you're using them.
So you'd need to either POST the form (as you're already doing) and handle the postback by redirecting your request to the new address, or use JavaScript to capture the field's value when a submit button is clicked and loading the new address in the browser window.
I'd suggest server-side is the best option as JavaScript might be disabled or unavailable.