How To Debug HTTP Error 400 in JSP - java

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>

Related

Why this html button sent get request?

this code sent get request, why?
<form th:action="#{/books/edit/rename}" th:object="${book}" th:method="POST">
<input type="text" id="id" name="id" th:value="*{id}" value="1"/>
<input type="text" id="bookName" name="bookName" th:value="*{bookName}" value="nameExample"/>
<button type="submit">Rename for model</button>
</form>
Try removing the th: in the method declaration, to be as the following:
<form th:action="#{/books/edit/rename}" th:object="${book}" method="POST">
…
Because it is not reading the code and the default is GET, check this for more details https://www.w3.org/TR/html401/interact/forms.html#h-17.3

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.

Pass parameters to url in jsp

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'" />

Spring MVC Posting Only Selected Data

This page displays several records when i select the Crime Number form the href tag i only want to post the data in that row only. Can someone tell me where i am going wrong here:
I did a different form for each record that returns from the server but only the first record gets returned all the time.
EDIT
The page is POST using java script and the Id its receiving is NULL
The crimeRecNo is posted accurately however the victim and criminal list only the first row is posted and not the selected one.Why????
function submitPage(crimeRecNo) {
document.getElementById("crimeList"+$('#crimeRecNo').val()).action = "getCrime/"+ crimeRecNo + ".htm";
document.getElementById("crimeList"+$('#crimeRecNo').val()).method = "POST";
document.getElementById("crimeList"+$('#crimeRecNo').val()).submit();
}
Html
</head>
<body>
<c:forEach items="${crimes}" var="crime">
<form:form id="crimeList${crime.crimeRecNo}" name="crimeList" commandName="crime">
<div id="content">
<div class="row-${crime.crimeRecNo}">
<h2>
<a class="crimeRecNo" href="${crime.crimeRecNo}">Crime Record
Number : ${crime.crimeRecNo}</a><form:input path="crimeRecNo" id="crimeRecNo"
value="${crime.crimeRecNo}" />
</h2>
<div class="crimeReport">
<label>${crime.crimeDetails}</label>
</div>
<div id="container">
<div id="crimePhotoz">
<div id="victimLabel">
<label class="heading">Victims/Witness In Crime</label>
</div>
<div class="grid_row">
<c:forEach items="${crime.victims}" var="victim">
<input type="hidden" value="${victim.photo}" class="foto" />
<canvas class="canvas" height="200" width="200"></canvas>
</c:forEach>
<c:forEach items="${crime.victims}" var="victim">
<div class="names">
<a class="crimeNames" href="${victim.socialSecurityNumber}">${victim.name}</a>
<form:input path="victims" id="victims" value="${victim.socialSecurityNumber}" />
</div>
</c:forEach>
</div>
<div id="criminalLabel">
<label class="heading">Criminals In Crime</label>
</div>
<div class="grid_row2">
<c:forEach items="${crime.criminals}" var="criminal">
<input type="hidden" value="${criminal.photo}" class="foto" />
<canvas class="canvas" height="200" width="200"></canvas>
</c:forEach>
<c:forEach items="${crime.criminals}" var="criminal">
<div class="names">
<a class="crimeNames" href="${criminal.socialSecurityNumber}">${criminal.name}</a>
<form:input path="criminals" id="criminals" value="${criminal.socialSecurityNumber}" />
</div>
</c:forEach>
</div>
</div>
</div>
</div>
<hr>
</div>
</form:form>
</c:forEach>
</body>
</html>
Maybe you are missing some quotes?
document.getElementById(${crime.crimeRecNo})
If ${crime.crimeRecNo} is a string this becomes
document.getElementById(myRecNo)
which is invalid javascript. In this case you should add quotes:
document.getElementById("${crime.crimeRecNo}")
If ${crime.crimeRecNo} is a number you don't need quotes but then you might have invalid ids. According to this html ids must at least start with a character. Iam not sure if this can cause problems but maybe you should try <form id="record-${crime.crimeRecNo}" .. >

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