Pass parameters to url in jsp - java

Is this right way to send parameter along with url in jsp page ?
<a href="CancelRequest?userid=<%=idperson%>&userrnamee=<%=namee%>" onclick="return confirm('Are you sure you want to cancel the request?');">
<input type="submit" value="CANCEL REQUEST"></input>
</a>
I tried this But its not taking up the namee field .Please help

sample code:
<input type="button" value="ADDUSER" class="button"
onclick="location.href='UserController?action=insert'"/></p>
<input type="button" value="BACK" class="button"
onclick="location.href='employeeCategory.jsp'" />

Related

Forms not supported in AMP

I have search functionality with form. Use method="post" but its not working gives "amp" error that invalid attribute "action".
I have also tried "action-xhr" but still its not working. Please if anyone has solution let me know.
This is my code:
<form method="post" action-xhr="<?php echo base_url(); ?>Search">
<div class="input-group col-md-5 col-xs-6">
<input type="text" name="proname" class="form-control input-lg" placeholder="Find Courses..." />
<span class="input-group-btn">
<button type="submit" class="btn btn-info btn-lg searchBtnBorder"> <i class="glyphicon glyphicon-search"></i> </button>
</span>
</div>
</form>
Thanks,
Are you using https in your action link? AMP forms must all be https
So you will need to use a full path and have SSL Cert installed
https://www.ampproject.org/docs/reference/components/amp-form
"Action must be provided, https"
If you use method "GET" you don't need to use https. Also, you must have target set to "_top" or "_blank" otherwise you won't validate.

No action attribute in html form for Jsoup login

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

onClick doesn't work when form action is going to jsp page with Apache Shiro

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.

How To Debug HTTP Error 400 in JSP

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>

Using post method along with jquery modal window

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="">

Categories