I'm using eclipse. I have a login form like this
<form method="post" action="login">
<p>Login</p>
<input type="text" id="email"/><br>
<input type="text" id="password"/><br>
<input type="submit" value="GET STARTED"/>
</form>
when I use request.getParameter("email") in the servlet, it doesn't give me the input value because I don't specify the name of input. So I add the name attribute.
<form method="post" action="login">
<p>Login</p>
<input type="text" id="email" name="email"/><br>
<input type="text" id="password" name="password"/><br>
<input type="submit" value="GET STARTED"/>
</form>
But still I don't get the input value. Then after 1+ hour of invalid debugging, I exit the eclipse. Then I restart the eclipse again, the problem is gone.
I guess does it have something to do with "how the IDE mapping form input values" and stuff? I tried clearing the cache of eclipse, but it turned out not related to the issue.
Anyone can explain what happened here? Thanks!
Update in 0504:
It has something to do with the IDE's web browser, although I don't know exactly what the problem is. I change to use the external Chrome and it works fine there.
The second code should have worked here. Its the name attribute that gets posted in the form submit. I guess, you forgot to save or the saved code was somehow not deployed in the Application server.
Related
I want to write a part of a website that lets the user alter the data of a pre existing book. For that, I am trying to use a form which works fine. I just can't figure out how to get the form to display data in the editing fields so the user doesn't have to enter everything again but can simply change some details. My HTML code looks like this:
<form method="post" role="form" class="ui form" id="bookForm" th:action="#{/editBook}" th:object="${bookForm}">
<div class="field">
<label for="name">Book</label>
<input id="name" name="name" th:field="*{name}" th:errorclass="fieldError" type="text" required="required"/><br/>
</div>
I include some more code about errors and other things but this is basically where I want the form not only to pass values to my java file but also to take values about the book and display them in the editing fields.
I think I need to pass the book that the user wants to edit into this form but I'm not sure how. I have tried:
<input type="hidden" id="currentBook" name="currentBook" th:value="${currentBook}"/>
right before the "div" statement and then passing the "currentBook" into HTML with
model.addAttribute("currentBook", currentBook);
in my #GetMapping method of that website. I then changed the "input" statement in my field as well to
<input id="name" name="name" th:field="*{name}" th:value="${currentBook.name}" th:errorclass="fieldError" type="text" required="required"/><br/>
currentBook.name will give me the name of that book just not within this context. Does anyone know what I'm doing wrong and how it will work?
Thank you in advance!
I am having a hard time trying to figure out the correct process for automating login for the following website: http://abelhas.pt
I have used Firefox's HttpFox plugin to discover the login form and action page url, in the generated HTML code and have found out that to perform login, I will need to post the following parameters:
Login=theLogin
Password=thePassword
Redirect=True
RedirectUrl=
RememberMe=false
FileId=0
The url to which the parameters are being passed when the user presses the submit button, is the following: "/action/login/login" (which is the one shown on the "action" attribute of the html element)
However, when generating and posting it using the following URL:
http://abelhas.pt/action/login/login?Login=theLogin&Password=thePassword&Redirect=True&RedirectUrl=&RememberMe=false&FileId=0
(Please note that the the values of "theLogin" and "thePassword" should be replaced by a valid login and password)
I am always getting "http://abelhas.pt/Error404.aspx", meaning that the following webpage was not found...
In the past, I have already been able to successfully automate logging-in in websites such as Google, filefactory, zippyshare, Imageshack, etc..however this one seems to be playing tricks on me...
Can someone help me understanding what is happening or what am I doing wrong?
Many thanks guys!
Gizmo
In my vaadin application i want to redirect to a website with automatic log in.
Now the issue is am unable to logIn through my java code which refers from
http://www.mkyong.com/java/how-to-automate-login-a-website-java-example/
Am also getting response code: 200, and unable to make use of response.
Following is the code snippet of the website to which i want to automate login
<form action="login.php" method="post" id="clientLogin">
<input type="hidden" name="__CSRFToken__" value="eac035fe0a1a64a9945e0ce798a44a52ca040b5c" /><div style="display:table-row">
<div class="login-box">
<strong></strong>
<div>
<input id="username" placeholder="Email or Username" type="text" name="luser" size="30" value="">
</div>
<div>
<input id="passwd" placeholder="Password" type="password" name="lpasswd" size="30" value=""></td>
</div>
<p>
<input class="btn" type="submit" value="Sign In">
</p>
</div>
<div style="display:table-cell;padding: 15px;vertical-align:top">
<div>
<!--<b>I'm an agent</b> —
sign in here
-->
</div>
</div>
</div>
</form>
I have a jQuery dialogue box which contains values as checkboxes. On selecting the checkboxes I am storing the selected values into label. Next I have to send these values from label as parameter through form to servlet but I don't know how to complete it.
Here is my code:
<form action="CallTimer" method="GET">
<label class="button2">Set Date: </label>
<input type="text" name="date" id="date" size="4">
<input type="Submit" name="Submit" value="Submit" id="Submit">
<br/>
Select Reporting Level
<label class="button2" style="display:none" id="depart"> Department</label>
</form>
I am retrieving these parameters in my Servlet as:
String reportname=request.getParameter("depart");
System.out.println(reportname);
But it is returning null values. Please help me.
Thanks in advance.
You have to use hidden input field:
<input type="hidden" name="depart" />
You need to understand what gets passed on form submission and what is not. In a nutshell, only values of the input fields get sent to the server. You have several ways to solve your problem:
Write value to a hidden input field
Modify the query string (what gets sent after ? in your GET request) during form submission (using java script):
?...&depart=xxx
I'm looking to create a hotel booking form that automatically generates a URL based on the information inputted into the form.
For example, if a person inputs the name of "John" and the date "12/23/1989" I need the form to generate a URL such as "fakeurl.com/n=JOHNd=12231989" and automatically direct to this link when the form is submitted.
Using a few tutorials (I don't know Java very well), I was able to piece this together:
http://codepen.io/JeremyMG/pen/ptaGE
However, I am unsure how to make the fields match up with the variables.
If anyone could give me a hand or post a working example, that would be great! Thanks guys.
<form method="GET" action="https://fakeurl.com">
<input type="text" name="n" value="john" />
<input type="date" name="d" value="12/23/1989" />
<input type="submit" value="submit" />
</form>
Set the FORM tag's METHOD attribute to GET
Using IE 7, JDK 1.6 and Sun Web server 7.
Inside the jsp form, we have:
<input type="text" name="id" maxlength="20" />
<input ... type="submit" name="send" value="Send"/>
i.e. a text box and a "Submit" button (called Send).
and the servlet has:
if (request.getParameter("send") != null && request.getParameter("send").trim().length() > 0) { ... }
Using Fiddler and IE, we can see that the following is sent when we populate the id text box and hit Enter:
id=123456
However, using Fiddler and IE, we can see that the following is sent when we populate the id text box and click the Send button:
userId=123456&send=Send
The end result is that hitting the Enter key effectively does nothing.
On other jsp pages, e.g. we have:
<input type="text" name="id" maxlength="20" />
<input ... type="submit" name="submitId" value="Submit"/>
and the servlet has:
if (request.getParameter("submitId") != null && request.getParameter("submitId").trim().length() > 0) { ... }
Using Fiddler and IE, we can see that the following is sent for both cases:
id=123456&submitId=Submit
So it seems to us that the behaviour is only exhibited on IE for forms where the "Submit" button is not called "Submit"?
Re-running the tests on Firefox 3.6 shows that the behaviour is correct and the same for both cases.
Any suggestions for getting IE to work correctly?
(Note: I have searched SO for a similar problem but the questions relating to this mainly all ASP related!).
This is indeed another IE anomaly in case of forms with only one input field. The only solid workaround for this is to add a second input field(!). You can hide it using CSS. No, type="hidden" ain't going to work.
<input type="text" name="id" maxlength="20" />
<input type="text" style="display: none;" />
<input type="submit" name="send" value="Send"/>
Why are you checking for request.getParameter("submitId") in your JSP when in fact submitId is the name of your submit button?
In my experience I never had to check the value for the submit button. I only used that button to trigger the form submit and would usually only be interested in retrieving the values for the other form parameters.
If you want to differentiate the submit methods by the name of the submit button, you might want to try adding a "hidden" property using input type="hidden".