html POST request login to website - html

Hi im trying to figure out how to login to a website using a post request.
I want to do this because i want to make a web app using particular data from content shown on the website after login.
However i cannot seem to figure out which url i need to use to login.
This is the FORM :
<FORM onSubmit="return checkrequired(this)" METHOD=POST ACTION="/pkmslogin.form">
<FONT SIZE="+2">
<TABLE BORDER="0" WIDTH="400">
<TR>
<TD ALIGN="LEFT"><UL><LI>Gebruikersnaam</LI></UL></TD>
<TD><INPUT TYPE="TEXT" NAME="username" SIZE="15" AUTOCOMPLETE="off">
</TD>
</TR>
<TR>
<TD ALIGN="LEFT"><UL><LI>Wachtwoord</LI></UL></TD>
<TD><INPUT TYPE="PASSWORD" NAME="password" SIZE="15" AUTOCOMPLETE="off"></TD>
<INPUT TYPE="HIDDEN" NAME="login-form-type" VALUE="pwd">
</TR>
</TABLE>
</FONT>
<BR>&nbsp <INPUT TYPE="SUBMIT" VALUE="Aanmelden">
The javascript checkrequired():
function checkrequired(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (((tempobj.type=="text"||tempobj.type=="password")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==0)) {
pass=false;
break;
}
}
}
if (!pass) {
shortFieldName=tempobj.name.substring(0,30).toUpperCase();
if (shortFieldName=="USERNAME") {
shortFieldName="Gebruikersnaam";
}
if (shortFieldName=="PASSWORD") {
shortFieldName="Wachtwoord";
}
alert("Het veld \""+shortFieldName+"\" is niet ingevuld.");
return false;
}
else
return true;
}
I thought i needed to use /?Username='...'&password='...' but this is not the case.
edit
Chrome developer tools tells me no variables are being passed to the pkmslogin.form
Path = pkmslogin.form
method = POST
Status = 302 Moved Temporarily
type = text/html
Initiator = Other
Size = 713 B 0 B
Time = 367 ms 366 ms

It seems that you are using IBM WebSEAL but instead of using its management page, you made your own
So, the problem is that you are sending the request to /pkmslogin.form but as your application is behind WebSEAL, so it must be accessed by a junction.
So, your request actually goes to:
https://WebSEAL_HOST:WebSEAL_Instance_Port/Your_Junction/Your_App_Context_Root/pkmslogin.form
You have two solution:
Use a relative URL:
../../Your_Junction/pkmslogin.form
Use an absolute URL: https://WebSEAL_HOST:WebSEAL_Instance_Port/pkmslogin.form

Related

Delete query using jsps

I'm new to JEE programming, I know that the way I present you my problem is not optimal but I have to do it using only JPSs first.
So, I created a form that included checkboxes. I would like to delete all members that have been checked. My tag action form redirects to dispaly.jsp where I perform delete query before redirecting to my main page, members.jsp.
The problem is that my server crash and does not redirect me. I have to restart it, But my rows have been deleted in my database.
Here's my code :
<form method="post" action="display.jsp"><table id="members_table">
<tr>
<th>Sel</th><th>FIRSTNAME</th><th>NAME</th><th>EMAIL</th>
</tr>
<%
while (resultset.next()) {
%>
<tr>
<td><input type="checkbox" name="selected" value="<%=resultset.getString(1)%>"/></td>
<td><%= resultset.getString(2)%></td>
<td><%= resultset.getString(3)%></td>
<td><%= resultset.getString(4)%></td>
</tr>
<%}%>
</table>
<input type="submit" value="Details" name="details" id="details_members">
<input type="submit" value="Delete" name="delete" id="delete_members">
</form>
display.jsp page :
RequestDispatcher requestDisp = request.getRequestDispatcher("/members.jsp");
if(request.getParameter("delete") != null)
{
if(request.getParameter("selected")!=null)
{
String[] a = request.getParameterValues("selected");
str = "DELETE FROM MEMBERS WHERE ID = ";
for(int it=0;it<a.length;++it)
{
if(it==a.length-1)
str+=a[it];
else
str+=a[it]+" OR ID = ";
}
statement.executeUpdate(str);
requestDisp.forward(request, response);
}
requestDisp.forward(request, response);
}
When I run my code, I get this error after a long time waiting :
javax.servlet.ServletException: java.sql.SQLTransactionRollbackException: Unable to get a lock within the requested timeout
root cause
java.sql.SQLTransactionRollbackException: Unable to get a lock within the requested timeout
I don't understand why my server crash, I tried to execute this delete query directly in my database and it works. I also debug my code to see if my variable "str" contains right query ...
Please help.

Can I make HTTP POST request from Thymeleaf table in Spring Boot application

I have a Thymeleaf template in a simple Spring Boot application. The template contains a list in a table as follows:
<p>There are <span th:text="${#lists.size(persons)}"></span> people:</p>
<table th:if="${not #lists.isEmpty(persons)}" border="1">
<tr>
<th>ID</th>
<th>Name</th>
<th>Address</th>
<th>Telephone</th>
<th>Email</th>
<th>Actions</th>
</tr>
<tr th:each="person : ${persons}">
<td th:text="${person.personId}"></td>
<td th:text="${person.name}"></td>
<td th:text="${person.address}"></td>
<td th:text="${person.telephone}"></td>
<td th:text="${person.email}"></td>
<td>
Edit |
Delete
</td>
</tr>
</table>
I want to enable edit and delete functionality as per the last cell in the table. But at the moment both requests are for HTTP GET. That is fine for edit where a person's details are fetched from the server for editing, but delete should trigger a POST request because of the data changes on the server.
Does anyone know if Thymeleaf allow a POST request per row of a table? Or do I have to write a simple HTML form per row?
The GET form is currently:
<td>
Edit
<!--a href="#" data-th-href="#{/delete(personId=${person.personId})}">Delete</a></td-->
<form method="get" th:action="#{/edit(personId=${person.personId})}">
<button type="submit" name="submit" value="value">Edit</button>
</form>
</td>
Where I have a link and a form for testing.
The controller method to be called is:
// Gets a Person.
#RequestMapping(value="/edit", method=RequestMethod.GET)
public String getEditPerson(#RequestParam("personId") String personId, Model model) {
logger.info(PersonController.class.getName() + ".getEditPerson() method called.");
Person person = personDAO.get(Integer.parseInt(personId));
model.addAttribute("person", person);
// Set view.
return "/edit";
}
The error when the button version of GET is called is:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Jul 24 00:26:16 BST 2016
There was an unexpected error (type=Bad Request, status=400).
Required String parameter 'personId' is not present`
I am using GET to trigger editing because no data is sent to the server here other than the personId. No database action is taken so it should be a GET.
you are using Links and I don't think that is possible, you would need to use a form where you can specify the method POST to be used.
In the example below im using a <button> instead of a <a> element, but it will work, the only thing you need to do is to style your button with CSS to look like your links
<form method="POST" th:action="#{/edit(personId=${person.personId})}">
<button type="submit" name="submit" value="value" class="link-button">This is a link that sends a POST request</button>
</form>
now in your code should look like this
<tr th:each="person : ${persons}">
<td th:text="${person.personId}"></td>
<td th:text="${person.name}"></td>
<td th:text="${person.address}"></td>
<td th:text="${person.telephone}"></td>
<td th:text="${person.email}"></td>
<td>
<form method="POST" th:action="#{/edit(personId=${person.personId})}">
<button type="submit" name="submit" value="value" class="link-button">EDIT</button>
</form> |
<form method="POST" th:action="#{/delete(personId=${person.personId})}">
<button type="submit" name="submit" value="value" class="link-button">DELETE</button>
</form>
</td>
</tr>
EDIT
As you just shared you Java code, in the controller you are expecting the personId not as a PathVariable, but as a RequestParam,
in that case your form should have that value...
edit your form and add the person id as follows.
<form method="POST" th:action="#{/edit}">
<input type="hidden" name="personid" id="personId" th:value="${person.personId}" />
<button type="submit" name="submit" value="value" class="link-button">This is a link that sends a POST request</button>
</form>
Notice also I changed the action of the form to be just /edit, as its what your controller looks like
Does anyone know if Thymeleaf allow a POST request per row of a table? Or do I have to write a simple HTML form per row?
HTML doesn't support POST request with links and you have to use forms (as Rayweb_on explained). But Thymeleaf allows you to define custom tags which helps a lot :
<a th:href="#{/edit(personId=${person.personId})}" custom:linkMethod="post">Edit</a>
... which would generate following HTML (assuming jQuery is available) :
Edit
Custom tag definition (without error checking to keep it simple) :
/**
* Custom attribute processor that allows to specify which method (get or post) is used on a standard link.
*/
public class LinkMethodAttrProcessor extends AbstractAttributeTagProcessor {
private static final String ATTR_NAME = "linkMethod";
private static final int PRECEDENCE = 10000;
public LinkMethodAttrProcessor(final String dialectPrefix) {
super(
TemplateMode.HTML, // This processor will apply only to HTML mode
dialectPrefix, // Prefix to be applied to name for matching
null, // No tag name: match any tag name
false, // No prefix to be applied to tag name
ATTR_NAME, // Name of the attribute that will be matched
true, // Apply dialect prefix to attribute name
PRECEDENCE, // Precedence (inside dialect's own precedence)
true); // Remove the matched attribute afterwards
}
#Override
protected void doProcess(final ITemplateContext context, final IProcessableElementTag tag,
final AttributeName attributeName, final String attributeValue,
final IElementTagStructureHandler structureHandler) {
// get the method name (tag parameter)
final IEngineConfiguration configuration = context.getConfiguration();
final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration);
final IStandardExpression expression = parser.parseExpression(context, attributeValue);
final String method = (String) expression.execute(context);
// add custom javascript to change link method
final String link = tag.getAttribute("href").getValue();
final String action = "$('<form action="" + link + "" method="" + method + ""></form>').appendTo('body').submit(); return false;";
structureHandler.setAttribute("onclick", action);
structureHandler.setAttribute("href", "#");
}
}
See the Thymelead documentation for example of how this custom attribute needs to be registered.

Why is my attempt to fetch and show MongoDB documents in my Meteor app crashing?

I'm trying to fetch and display some MongoDB documents in my Meteor app. I am trying to use the docs here as a basis for this.
The HTM I've added is this:
{{> placesLived}}
. . .
<template name="placesLived">
<table style="width:60%">
{{#each places}}
<tr>
<td>{{ts_city}}</td>
<td>{{ts_state}}</td>
<td>{{ts_yearin}}</td>
<td>{{ts_yearout}}</td>
</tr>
{{/each}}
</table>
</template>
...so that the entire .html file is now this:
<head>
<title>timeandspace</title>
</head>
<body>
<h1>A List of the Places I Have Lived</h1>
{{> addTimeSpaceForm}}
{{> placesLived}}
</body>
<template name="addTimeSpaceForm">
<form>
<label for="city">City</label>
<input type="text" name="city" id="city">
<br/>
<label for="state">State</label>
<input type="text" name="state" id="state">
<br/>
<label for="yearin">Year Arrived</label>
<input type="text" name="yearin" id="yearin">
<br/>
<label for="yearout">Year Departed</label>
<input type="text" name="yearout" id="yearout">
<br/>
<input type="submit" name="insertdocument" id="insertdocument" value="Add Place Lived">
</form>
</template>
<template name="placesLived">
<table style="width:60%">
{{#each places}}
<tr>
<td>{{ts_city}}</td>
<td>{{ts_state}}</td>
<td>{{ts_yearin}}</td>
<td>{{ts_yearout}}</td>
</tr>
{{/each}}
</table>
</template>
The Javascript I've added is this:
Template.placesLived.helpers({
places: function () {
// this helper returns a cursor of all of the documents in the collection
return TimeAndSpace.find();
}
});
...so that the entire .js file is now this:
TimeAndSpace = new Mongo.Collection('timeAndSpace');
if (Meteor.isClient) {
Template.addTimeSpaceForm.events({
'submit form': function(event){
event.preventDefault();
var city = event.target.city.value;
var state = event.target.state.value;
var yearin = event.target.yearin.value;
var yearout = event.target.yearout.value;
Meteor.call('insertLocationData', city, state, yearin, yearout);
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
Meteor.methods({
'insertLocationData': function(city, state, yearin, yearout){
console.log('attempting to insert a record');
TimeAndSpace.insert({
ts_city: city,
ts_state: state,
ts_yearin: yearin,
ts_yearout: yearout
});
}
});
}
Template.placesLived.helpers({
places: function () {
// this helper returns a cursor of all of the documents in the collection
return TimeAndSpace.find();
}
});
My notion of what is supposed to happen here is that the "placesLived" template is added to the page, which template calls the "places" function in the js file -- which returns all the TimeAndSpace documents -- and finally the "placesLived" template loops through those returned documents, placing each field in a "td"
However, saving these changes (which restarts the Meteor app) wreaks havoc in the Meteor field: the command prompt cast the following aspersions (not to be confused with asteroids) on me:
The Meteor machine is obviously not amused. What have I fouled in my code / what needs to change?
Your helper is running on the client & server. Put an isClient around it & you'll be fine.
Anytime you get pretty purple/blue colors on the console it means something is wrong with your server. When it says Template is not defined that tells you the server can't find something called Template.

Uploading video files in the mysql database

This code can upload video files but only to my specific folder. How can I upload the video files into my database and retrieve it for viewing/streaming. Could you help me please? I have read something about just not uploading it to the database but uploading it to the server? What does that means?
This is my view:
<body>
<div id="container">
<h1>Welcome</h1>
<div id="body">
<div id="div2">
<div id="upload">
<form class="cssform" name="property" id="property" method="POST" action="<?php echo base_url()?>main/add_video" enctype="multipart/form-data" >
<table>
<tr>
<td><input type="file" id="video" name="video" ></td>
</tr>
<tr>
<td> <input type="submit" id="button" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
</div>
<a href='<?php echo base_url()."main/logout" ?>'>Logout</a>
</div>
<div id ="searchBox">
</div>
</div>
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>
</body>
This is my controller:
public function add_video(){
if (isset($_FILES['video']['name']) && $_FILES['video']['name'] != '') {
unset($config);
$date = date("ymd");
$configVideo['upload_path'] = './videos';
$configVideo['max_size'] = '10240';
$configVideo['allowed_types'] = 'avi|flv|wmv|mp3';
$configVideo['overwrite'] = FALSE;
$configVideo['remove_spaces'] = TRUE;
$video_name = $date.$_FILES['video']['name'];
$configVideo['file_name'] = $video_name;
$this->load->library('upload', $configVideo);
$this->upload->initialize($configVideo);
if (!$this->upload->do_upload('video')) {
echo $this->upload->display_errors();
} else {
$videoDetails = $this->upload->data();
echo "Successfully Uploaded";
}
}
}
You do NOT want to upload to the database...that would become an enormous amount of data to be unnecessarily managed by MySQL, not to mention a huge development undertaking to view the videos.
You could change your code to determine what folder it should be uploaded to, and move it there after the upload to .videos\ is complete. Perhaps by username, or date or similar, and have a table in your database that stores the folder name of where the file is located and other video related information.
At that point, you can use MySQL to locate the files, and other info you've stored, and use that to create a valid link to view the video, which would be in the folder that it was moved to.

HTML table cells overlapping on Blackberry

I have the following HTML code:
<table><tr>
<td>Search: </td>
<td>'.GetCategoryDropdownList().'</td>
<td>for: </td>
<td class="input">
<input class="header-right-search" type="text" name="q" placeholder="Search by Book Name, Author, Module Code, or Module Name" style="width: 100%;" />
</td>
<td><input type=submit value="GO" class="yellowhighlightbutton" /></td>
</tr></table>
where "GetCategoryDropdownList()" just returns the HTML for a simple dropdown menu.
This table displays fine in all web browsers (including on android/iphone/etc), with each table cell nicely spaced, but on Blackberry the cells end up overlapping.
Do you know why this is happening or any way to fix it?
Thanks
GetCategoryDropdownList() is
function GetCategoryDropdownList()
{
$query = sprintf("SELECT %scategorylist.* FROM %scategorylist", dbprefix, dbprefix, dbprefix);
$catlist = DbQuery($query);
$catselect = '<select class="header-category-select" name="category_select">';
foreach($catlist as $cat)
{
if($cat['Code'] == 'catAll')
{
$catselect = $catselect.sprintf("<option class=\"header-category-option\" value=\"%s\" selected=\"selected\">%s</option>",$cat['Code'],$cat['Name']);
}
else
{
$catselect = $catselect.sprintf("<option class=\"header-category-option\" value=\"%s\">%s</option>",$cat['Code'],$cat['Name']);
}
}
$catselect = $catselect.'</select>';
return $catselect;
}
All it does is make a dropdown menu, which displays correctly on every platform except blackberry.
Can you give the GetCategoryDropdownList() code? Have you also set the correct headers for displaying in a mobile website? For blackberry browser you can use
<meta name=”HandheldFriendly” content=”True” />
Check it out: http://docs.blackberry.com/en/developers/deliverables/6176/HTML_ref_meta_564143_11.jsp