I am developing an application using jquery ui and servlets.I have used modal dialog window for login.Once I Login the credentials are being sent to LoginServlet where the crendentials are checked and the user is being redirected to new page.
now Login.jsp has:
<html>
<head>
<script>
$(document).ready(function() {
$("#dialog").dialog();
</script>
</head>
<body style="font-size: 62.5%;">
<div id="dialog" title="DBoperations">
<form id="LoginForm" method="post" action="Login">
<fieldset>
<label>Username:</label>
<input type="text" id="username" value=""></input><br></br>
<label>Password:</label>
<input type="password" id="password" value=""></input><br></br>
<input type="submit" id="submit" class="submit" value="Log In" align="middle"></input>
</fieldset>
</form>
</div>
</body>
Now when I run the application the data passed to the servlet is null.I checked it using println statements.As far as I know al it takes to pass data to servlet is specifying action and using getparameter on server side...
I am gettin Null pointer exception due to the null value being passed to the login method..
why are null values passed??
Try adding a name attribute to your inputs and see if that works. I believe the browser only sends the request parameter if it has a name attribute.
<input type="text" id="username" name="username" value="">
Related
I'm trying to login a website (vimla.se) using Jsoup in android. I'm aware that when submitting forms in html, action is the attribute which we use to POST the login credentials using Jsoup (as explained here). However, in my case, there's no action pointer and the html form looks something like this:
<form id="loginForm" name="loginForm" ng-submit="login()" method="POST">
<input type="email" id="username" form-filler required="required" class="text txtEmail" name="username" placeholder="E-mail" autofocus="autofocus" ng-model="username" />
<br />
<input type="password" id="password" required="required" class="text txtPass" name="password" form-filler placeholder="Password" autofocus="autofocus" ng-model="password" />
<br />
<button type="submit" class="btn" ng-disabled="sending">Login</button>
</form>
So my question is, how do we login such forms using Jsoup?
This is actually a form using Angular.js. The action - attribute is not specified, but ng-submit https://docs.angularjs.org/api/ng/directive/ngSubmit
describes what to do on submit. The LoginController then implements the function that gets executed. Its implementation is hidden in https://vimla.se/scripts/all.min.js?v=1.0.0.0.
a.login=function(){a.sending||(a.sending=!0,a.error=!1,b.post("/user/login",{username:a.username,password:a.password,referer:a.referer})
So the url that gets called is /user/login and the parameters transmitted are username, password, referer
I was originally logging in fine, while needing to submit an onClick method before my form is submitted (as it helps with some of the data sent).
I am now trying to send some of this info to my Java Bean using
<jsp:useBean id="url" class="plan.URL" scope="session"/>
<jsp:setProperty name="url" property="*"/>
The problem I am encountering is that my login is not submitting correctly which seems to mean that when I set
action=""
to
action="viewer.jsp" it isn't calling my onClick method anymore, or at least that's what it seems to be.
Login
<form name="loginform" action="viewer.jsp" method="POST" accept-charset="UTF-8" role="form">
<fieldset>
<div class="form-group">
<input class="form-control" id="user" placeholder="User Name" name="user" type="text">
</div>
<div>
<input class="form-control" placeholder="Password" name="password" type="password" value="">
</div>
<input class="btn btn-lg btn-primary btn-block" type="submit" value="Login" onClick = "login()" >
</fieldset>
</form>
Any advice?
Thanks!
EDIT: I realized that for some reason I wasn't being logged in at all once I put an action. I am using Apache Shiro so I am wondering what's going on with the Authentication.
onclick is conflicting with submit: submit causes the page to reload. onclick might be called but the browser will load the action page at the same time.
Change input's onclick to form's onsubmit then do your login() stuff and return true from it if you want the form to be finally submitted, or false if you don't validate the data and you want to cancel the submition.
onsubmit is an attribute to the <form> element, so you'd do:
... to submit the form depending on your login() function result (true->submit, false->don't submit):
<form onsubmit="return login()" .........>
... to execute login() function and ALWAYS submit afterwards, you can also do:
<form onsubmit="login();return true;" .........>
and just
<input type="submit" ...>
without any event.
HTML Page
<form action="viewParticularImage.jsp" method="post">
input type="submit" name="1" value="Details" />
input type="submit" name="2" value="Details" />
input type="submit" name="3" value="Details" />
</from>
JSP page
<%
String name = request.getParameter("name");
out.write(name);
%>
i am getting null value in name while printing the button Details in JSP Page pls help to find the solution, thanks to the replies in advance .
You have parameters named as "1", "2" and "3", but you have not parameter named as "name".
<form action="viewParticularImage.jsp" method="post">
<input type="submit" name="name" value="Details" />
...
</from>
In your JSP page make it
<%
String name = request.getParameter("1");
out.write(name);
%>
You are not sending a parameter named name in the request.That's why! To confirm, try
<%
String name = request.getParameter("1");
out.write(name);
%>
Your form should be like below. See the value of name attribute of the input text. The name attribute denotes the name of the request parameter
<form action="viewParticularImage.jsp" method="post">
First name: <input type="text" name="name"><br>
<input type="submit" value="Submit">
</form>
Note : Try entering a value in the text and submit. You will receive it in the server request
I believe you haven't gained any knowledge regarding HTML ... First, go and check the tutorials regarding HTML...
Let's get to the game ... What are you trying to do ... Are you trying to pull down values set to the submit button ... or you are trying to publish a textfield where user can type their name and show that name as the result in the next page ????
If you are trying to publish the values assigned to the submit button...
HTML Page
<form action="viewParticularImage.jsp" method="post">
<input type="submit" name="1" value="Details" />
<input type="submit" name="2" value="Details" />
<input type="submit" name="3" value="Details" />
</form>
JSP page
<%
String name = request.getParameter("1");
out.write(name);
%>
If you are trying to publish what users type ...
HTML Page
<form action="viewParticularImage.jsp" method="post">
<input type="text" name="name" />
<input type="submit" value="Hit Send" />
</form>
JSP page
<%
String name = request.getParameter("name");
out.write(name);
%>
I think this clarifies you how things work !!!! Thank you ... peace !!!
I have the following code that prints some links on the page, and is supposed to call a controller method (launch), upon clicking the image. However, I am getting an Error 400 when I click the button. The generated links look correct to me. The code is in the 1st block. The actual View-Source is in the 2nd.
Unfortunately, I am not getting any errors in my server logs, so I don't know where to begin to debug this.
Does anyone see anything wrong with my code.
<div id="links">
<ul>
<c:forEach items="${listAppURLForm}" var="appURLForm">
<li>
<h2>${appURLForm.link}</h2>
<p>
<span>
<form method="post" action='<c:url value="launch"/>'>
<input type="hidden" name="id" value="${appURLForm.link}"/>
<input type="image" src='<c:url value="/images/rocket-thumbnail.png"/>'/>
</form>
</span>
</p>
</li>
</c:forEach>
</ul>
</div>
The rendered page:
<form method="post" action='launch;jsessionid=40d63cd386e5d01ef8c6dc1c1b76'>
<input type="hidden" name="id" value="http://www.cnn.com"/>
<input type="image" src='/services/images/rocket-thumbnail.png;jsessionid=40d63cd386e5d01ef8c6dc1c1b76'/>
</form>
400 means server cant understand what browser sent
your action='launch;jsessionid=40d63cd386e5d01ef8c6dc1c1b76' might be ?launch;jsessionid=40d63cd386e5d01ef8c6dc1c1b76
<form method="post" action='?launch;jsessionid=40d63cd386e5d01ef8c6dc1c1b76'>
<input type="hidden" name="id" value="http://www.cnn.com"/>
<input type="image" src='/services/images/rocket-thumbnail.png;jsessionid=40d63cd386e5d01ef8c6dc1c1b76'/>
</form>
I'm starting from here :
With that code :
<!DOCTYPE html>
<html>
<head><title>Bank application</title>
<link rel="stylesheet"
href="./css/styles.css"
type="text/css"/>
</head>
<body>
<table class="title">
<tr><th>Web Bank application</th></tr>
</table>
<br/>
<fieldset>
<legend>Login Page - please enter your Username and Password</legend>
<form action="loginPage">
Username: <input type="text" name="username"><br>
Password : <input type="text" name="password"><br>
<input type="submit" value="Login">
</form>
</fieldset>
<br/>
<br/>
<br/>
<fieldset>
<legend>Registration</legend>
<form action="register">
First name: <input type="text" name="firstName"><br>
Last name : <input type="text" name="lastName"><br>
Address : <input type="text" name="address"><br>
ID-number : <input type="text" name="idnumber"><br>
User-Name : <input type="text" name="userName"><br>
Password : <input type="text" name="password"><br>
<input type="submit" value="Register">
</form>
</fieldset>
<br/>
<br/><br/><br/><br/><br/><br/>
</body></html>
And while I move from one page to another , I reach here :
With that code :
<!DOCTYPE html>
<html>
<head><title>Authentication failed - a problem has occurred!</title>
<link rel="stylesheet"
href="./css/styles.css"
type="text/css"/>
</head>
<body>
<h1>Sorry , but you are not registered to our bank!</h1>
<fieldset>
<legend>Please press here to continue</legend>
<form action="goingBack">
<input type="submit" value="Press here">
</form>
</fieldset>
</body></html>
And I want to go back to index.html - the first page that I see when the program starts (the first picture above) .
How can I do that ? how can I forward back to index.html ?
Regards
Just add a link to the previous page in the last HTML:
<!DOCTYPE html>
<html>
<head><title>Authentication failed - a problem has occurred!</title>
<link rel="stylesheet"
href="./css/styles.css"
type="text/css"/>
</head>
<body>
<h1>Sorry , but you are not registered to our bank!</h1>
<fieldset>
<legend>Please press here to continue</legend>
<form action="goingBack">
<input type="submit" value="Press here">
</form>
</fieldset>
Go Back <!-- add this -->
</body></html>
You just need javascript. To redirect to /index.html after 5 seconds :
setTimeout('window.location='index.html';', 5000);
setTimeout() is a javascript function that sets a timer to trigger somehting after a given period of time. window.location is a variable that allows you to change the URL of the current page (thus redireting).