php mailform with JAvascript validation - java

I'm having a problem with my one page contact form.
When i click the submit button, i run a javascript check to see if the fields are filled.
The check works fine but i don't have any clue why the PHP isn't responing.
i can't use another php page to do the processing because i want to use the same contact page for other contact purposes.
So this is the sequence i want to get:
1. Form gets filled in
2. On click of the submit butten, javascript checks the fields.
3. If okay, javascript submits the form
4. if mail has been sent, the page is reloaded to contact.php?MailStatus=Success
5. if not (it will run a javascript giving en errormessage telling the user to retry without the fields being cleared.
contact.php (code)
<!DOCTYPE html>
<html>
<head>
<title>Mijn Dier En Ik</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="www.csl-tech.be" />
<meta name="description" content="Op zoek naar dierenhotels, artsen, winkels,... Dan is Mijn Huisdier en Ik de website die je zoekt. Neem een kijkje!" />
<link rel="stylesheet" type="text/css" href="CSLCSS.css">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="functions.js"></script>
</head>
<body>
<div class="container csl-main">
<div class="row">
<div class="col-md-6">
<form id="MailForm" method="post">
<div id="Message"></div>
<div id="FormFields">
<div class="form-group">
<label for="fname">Voornaam</label>
<input class="form-control" type="text" id="fname" placeholder="Uw voornaam...">
</div>
<br />
<div class="form-group">
<label for="lname">Achternaam</label>
<input class="form-control" type="text" id="lname" placeholder="Uw achternaam...">
</div>
<br />
<div class="form-group">
<label for="email">E-mail</label>
<input class="form-control" type="text" id="email" placeholder="Uw e-mail...">
</div>
<br />
<div class="form-group">
<label for="country">Land</label>
<select class="form-control" id="country" name="country">
<option value="Belgie">Belgiƫ</option>
<option value="Nederland">Nederland</option>
</select>
</div>
<br />
<div class="form-group">
<label for="subject">Onderwerp</label>
<select class="form-control" id="subject" name="subject">
<option value="Vragen">Vragen over Mijn Dier en Ik</option>
<option value="Suggesties">Suggesties voor de website</option>
<option value="Reservatie of Contact">Vragen over het reservatie- en/of contactsysteem</option>
<option value="Foto inzending">Foto inzenden</option>
<option value="Aanpassing gegevens">Aanpassing gegevens</option>
<option value="Andere">Andere</option>
</select>
</div>
<br />
<div class="form-group">
<label for="message">Uw bericht</label>
<textarea class="form-control" id="message" placeholder="Typ hier uw bericht..." style="height:200px"></textarea>
</div>
<br />
<input id="submit" class="btn btn-default" value="Versturen" onclick="CheckMailEntry()">
</div>
</form>
</div>
</div>
</div>
</body>
<?php
if ($_GET['MailStatus'] == 'Success') {
echo '<script type="text/javascript">MailSuccess()</script>';
}
if(isset($_POST['submit'])) {
header('Location: contact.php?MailStatus=Success');
echo 'ok';
}
?>
</html>
Javascript code:
function CheckMailEntry() {
document.getElementById("Message").innerHTML = "";
if (document.getElementById("fname").value == "") {
document.getElementById("Message").innerHTML = "<div class='alert alert-danger'><strong>Fout:</strong> Voer uw voornaam in.</div>";
} else if (document.getElementById("lname").value == "") {
document.getElementById("Message").innerHTML = "<div class='alert alert-danger'><strong>Fout:</strong> Voer uw achternaam in.</div>";
} else if (document.getElementById("email").value == "") {
document.getElementById("Message").innerHTML = "<div class='alert alert-danger'><strong>Fout:</strong> Voer uw email in.</div>";
} else if (document.getElementById("message").value == "") {
document.getElementById("Message").innerHTML = "<div class='alert alert-danger'><strong>Fout:</strong> Gelieve een bericht te typen.</div>";
} else {
document.getElementById("Message").innerHTML = "";
document.getElementById("submit").submit();
};
};
function MailSuccess() {
document.getElementById("Message").innerHTML = "<div class='alert alert-success'><strong>Succes:</strong> Wij hebben uw mail ontvangen en zullen deze zo snel mogelijk beantwoorden.</div>";
document.getElementById("FormFields").innerHTML = "";
};

Related

Java. Thymeleaf. After CRUD operation all .CSS styles on page disappearing

A have simple CRUD web application. And I want to bind UI and backend with thymeleaf. After I create some data and get server response - all styles are disappearing. I'm new to thymeleaf, CSS and HTML. Can someone help me to figure out where is the problem?
Before and after:
Save operation method:
#PostMapping("/user/save")
public ModelAndView save(#ModelAttribute("userDTO") #Valid UserDTO userDTO,
BindingResult bindingResult, WebRequest request, Errors errors) {
User registered = new User();
if (!bindingResult.hasErrors()) {
registered = createUserAccount(userDTO, bindingResult);
}
if (registered == null) {
bindingResult.rejectValue("email", "message.regError");
}
if (bindingResult.hasErrors()) {
bindingResult.getAllErrors().forEach(error -> log.error(error.toString()));
return new ModelAndView("authorization/registration", "error", bindingResult.getAllErrors());
} else {
return new ModelAndView("users", "user", userDTO);
}
}
registration.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>User Registration</title>
<div th:replace="fragments/css_fragments :: css_background_layer"></div>
</head>
<body>
<div style="text-align:center">
<div th:replace="fragments/menu_fragments :: header_menu"></div>
</div>
<div style="margin: 0 auto; width: 20%; padding-top: 18%;">
<div class="registration-form">
<!--/*#thymesVar id="userDTO" type="com.socnetw.socnetw.model.UserDTO"*/-->
<form id="form" method="post" action="/user/save" th:object="${userDTO}">
<label>
<input name="username" placeholder="Username" required="required" th:field="*{username}"
type="text">
</label>
<ul>
<li th:each="err : ${#fields.errors('username')}" th:text="${err}"></li>
</ul>
<label>
<input name="realName" placeholder="Real Name"
type="text" th:field="*{realName}">
</label>
<ul>
<li th:each="err : ${#fields.errors('realName')}" th:text="${err}"></li>
</ul>
<span></span><br>
<label>
<input name="email" placeholder="Email" required="required" th:field="*{email}"
type="email">
</label>
<ul>
<li th:each="err : ${#fields.errors('email')}" th:text="${err}"></li>
</ul>
<label>
<input name="phoneNumber" placeholder="Phone Number" required="required" th:field="*{phoneNumber}"
type="tel">
</label>
<ul>
<li th:each="err : ${#fields.errors('phoneNumber')}" th:text="${err}"></li>
</ul>
<span></span><br>
<label>
<input name="password" placeholder="Password" th:field="*{password}"
required="required" type="password">
</label>
<ul>
<li th:each="err : ${#fields.errors('password')}" th:text="${err}"></li>
</ul>
<label>
<input name="passwordMatcher" placeholder="Repeat password" th:field="*{matchingPassword}"
required="required" type="password">
</label>
<ul>
<li th:each="err : ${#fields.errors('matchingPassword')}" th:text="${err}"></li>
</ul>
<span></span><br>
<button type="submit" style="margin-top: 20px">Register</button>
</form>
</div>
</div>
</body>
</html>
css fragment
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">
<div th:fragment="css_background_layer">
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"
rel="stylesheet"
th:href="#{'https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css'}"
type="text/css">
<link href="css/style.css" rel="stylesheet"
th:href="#{css/style.css}"
type="text/css">
<div class="overlay"></div>
</div>
</html>
You need to use an absolute url to your css, rather than a relative one. When you go to /user/save it's looking for /user/save/css/style.css -- which probably doesn't exist.
th:href="#{/css/style.css}"

Could not get values from request.getParameter Java JSP

Below is my code where i would be using to pass data to another domain. I am having this problem where with request.getParameter("accType"); the value could not be retrieved. However , other value is working fine, the names are correct and form has a post method on it, can anybody help me with this? Thanks in advance.
<%--
Document : viewEmployee
Created on : Jan 23, 2018, 12:06:44 AM
Author : AaronLee
--%>
<%#page import="java.sql.ResultSet"%>
<%# page import = "da.employeeDA" %>
<jsp:useBean id="employeeDA" class="da.employeeDA" scope="application" ></jsp:useBean>
<jsp:setProperty name="employeeDA" property="*" />
<%--import domain page--%>
<%# page import = "domain.employee" %>
<jsp:useBean id="employee" class="domain.employee" scope="application" ></jsp:useBean>
<jsp:setProperty name="employee" property="*" />
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%!
ResultSet rs = null;
%>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<%--import css--%>
<link href="font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
<link href="css/website.css" rel="stylesheet" type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%--Bootstrap CSS--%>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="HandheldFriendly" content="true">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
<title>Account Details</title>
</head>
<body>
<div class="wrapper">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="homepage.jsp">Document</a>
</div>
<ul class="nav navbar-nav">
<li>+ Document</li>
<li class="active">+ Claim</li>
<li>Search Document</li>
<li>Search Claim</li>
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Account<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Log Out</li>
</ul>
</li>
</ul>
</div>
</nav>
<div class="content">
<%
//login session
String username = null;
if (session.getAttribute("username") == null) {
response.sendRedirect("Login.jsp");
username = null;
return;
} else {
username = session.getAttribute("username").toString();
}
%>
<% try {
rs = employeeDA.searchEmployee(username);
} catch (Exception ex) {
ex.getMessage();
}
if (rs.next()) {
%>
<form method="POST" action="viewEmployee.jsp" >
Account Type :<br/>
<input type="text" value="<%=rs.getString("ACCTYPE")%>" name="accType" disabled /><br/><br/>
Employee ID :<br/>
<input type="text" value="<%=rs.getString("EMPLOYEEID")%>" name="employeeID" disabled/><br/><br/>
Name : <br/>
<input type="text" value="<%=rs.getString("EMPLOYEENAME")%>" name="employeeName"/><br/><br/>
Contact Number :<br/>
<input type="text" value="<%=rs.getString("EMPLOYEECONTACTNO")%>" name="employeeContactNo"/><br/><br/>
<div class="panel-group" id="panelGrp">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" href="#collapse1">Password</a>
</h4>
</div>
<div id="collapse1" class="panel-collapse collapse">
<div class="panel-body">Current Password :<br/>
<input type="text" class="form-control"/><br/>
New Password : <br/>
<input type="password" class="form-control" name="password"/><br/>
Confirm Password : <br/>
<input type="password" class="form-control" /><br/>
<input type="submit" value="Change Password" name="selection" class="btn btn-primary btn-lg btn-square" id="changepw"/>
</div>
</div>
</div>
</div>
<input type="submit" value="Update" id="changepw" name="selection" class="btn btn-primary btn-lg btn-square"/>
</form>
<%}%>
</div>
<div class="footer"></div>
</div>
</body>
</html>
<%if (request.getMethod().equals("POST")) {
if("Update".equals(request.getParameter("selection"))){
try{
employeeDA.updateEmployee(employee);
}catch(Exception ex){
ex.getMessage();
}
}else if("Change Password".equals(request.getParameter("selection"))){
try{
employeeDA.changePassword(username,request.getParameter("password"));
}catch(Exception ex){
ex.getMessage();
}
}
}
out.println(request.getParameter("accType"));
out.println(employee.getAccType());
%>
disabled elements in a form will not be submitted. You may have to use readonly.

Htmlunit redirect does not work

I am using version 2.28, I am having some issues trying to click a
button that redirects me twice to different URLs.
The result of the click method it is an UnexpectedPage ... (response
status code 200).
I tried to set:
webClient.getCache().setMaxSize(0);
webClient.getOptions().setRedirectEnabled(true);
but I can't reach the page after. I have JavaScript enable.
this is a web written in PHP
the button is currently doing this:
$.ajax({
url: '{{ action('LoanController#checkLoanProcessed') }}',
data: data,
type: 'POST',
cache: false,
dataType: "json",
success: function(data) {
if (data.status === true && data.processed === true)
{
clearInterval(interval); window.location.href = data.redirect; }
}
});
};
Any clue ?
HTML
<script>var SITE_URL = 'https://staging.tutasa.com.uy/';</script>
<script type="text/javascript">
var user_id = '49095';
var user_first_name = 'JUAN';
var duration_6 = "6 Months";
var duration_1 = '1 Year';
var duration_2 = '2 Years';
var duration_3 = '3 Years';
var duration_4 = '4 Years';
var duration_6_quota = '6 Quotas';
var duration_1_quota = '12 Quotas';
var duration_2_quota = '24 Quotas';
var duration_3_quota = '36 Quotas';
var duration_4_quota = '48 Quotas';
var quota_label = [];
quota_label['quota_0'] = '6 Monthly Quotas of:';
quota_label['quota_1'] = '12 Monthly Quotas of:';
quota_label['quota_2'] = '24 Monthly Quotas of:';
quota_label['quota_3'] ='36 Monthly Quotas of:';
quota_label['quota_4'] = '48 Monthly Quotas of:';
var borrower_page = true;
var lender_page = false;
</script>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
TuTasa - Your Account </title>
<link rel="stylesheet" type="text/css" href="https://staging.tutasa.com.uy/layouts/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="https://staging.tutasa.com.uy/layouts/css/datepicker3.css">
<link rel="stylesheet" type="text/css" href="https://staging.tutasa.com.uy/css/app.css?1512484810">
<link rel="stylesheet" type="text/css" href="https://staging.tutasa.com.uy/css/app2.css?1512484810">
<link rel="stylesheet" type="text/css" href="https://staging.tutasa.com.uy/layouts/css/bootstrap-slider.css">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://staging.tutasa.com.uy/layouts/js/jquery.min.js"></script>
<script type="text/javascript">
var CURRENCY_SYMBOL = '$U';
var CURRENCY_THOUSAND_SEP = ',';
var CURRENCY_DEC_POINT = '.';
var THOUSAND_SEP = ',';
var DEC_POINT = '.';
</script>
</head>
<body>
<div id="wrap" class="container-fluid">
<div id="main" class="row clearfix">
<div class="col-sm-offset-2 col-sm-8 col-md-offset-1 col-md-10 main">
<div class="container-fluid create-new-loan ">
<div class="panel panel-default">
<div class="panel-body pl0 pr0">
<div class="row bs-wizard" style="border-bottom:0;">
<div class="col-xs-3 bs-wizard-step complete">
<div class="progress"><div class="progress-bar"></div></div>
1
<div class="text-center bs-wizard-stepnum">1. Personal</div>
</div>
<div class="col-xs-3 bs-wizard-step active"><!-- complete -->
<div class="progress"><div class="progress-bar"></div></div>
2
<div class="text-center bs-wizard-stepnum">2. Income</div>
</div>
<div class="col-xs-3 bs-wizard-step disabled"><!-- complete -->
<div class="progress"><div class="progress-bar"></div></div>
3
<div class="text-center bs-wizard-stepnum">3. Decision</div>
</div>
<div class="col-xs-3 bs-wizard-step disabled"><!-- active -->
<div class="progress"><div class="progress-bar"></div></div>
4
<div class="text-center bs-wizard-stepnum">4. Money</div>
</div>
</div>
<form method="POST" action="https://staging.tutasa.com.uy/loan/create" accept-charset="UTF-8" class="form-horizontal"><input name="_token" type="hidden" value="BXLImooTL1DnEn4ouSi4uCJ1GG4fZawTdRkRzDtG">
<input name="int" type="hidden" value="">
<input name="user_id" type="hidden" value="49095">
<input name="type" type="hidden" value="borrower">
<div class="panel panel-default hidden">
<div class="panel-heading">Income</div>
<div class="panel-body">
<input type="hidden" name="borrow_amount_min" value="10000.00"/>
<input type="hidden" name="borrow_amount_max" value="200000.00"/>
<div class="form-group">
<label for="education" class="col-sm-4 control-label">Education<span class="required"> *</span></label>
<div class="col-sm-4">
<select class="form-control" id="education" name="education"><option value=""></option><option value="1">Primary</option><option value="2">Secondary</option><option value="3">University</option><option value="4" selected="selected">Post Graduate</option><option value="5">Other</option></select>
</div>
</div>
<div class="form-group">
<label for="income_type" class="col-sm-4 control-label">Means of Income<span class="required"> *</span></label>
<div class="col-sm-4">
<select class="form-control" id="income_type" name="income_type"><option value=""></option><option value="1">Employee</option><option value="2">Businessman</option><option value="3">Independent Professional</option><option value="4">Pension</option><option value="5">Allowances</option><option value="6" selected="selected">Rent</option><option value="7">Unemployed</option></select>
</div>
</div>
<div class="hidden income-employee income-1">
<div class="form-group">
<label for="company_name" class="col-sm-4 control-label">Company Name<span class="required"> *</span></label>
<div class="col-sm-4">
<input class="form-control" name="company_name" type="text" value="" id="company_name">
</div>
</div>
<div class="form-group">
<label for="job_title" class="col-sm-4 control-label">Job Title</label>
<div class="col-sm-4">
<input class="form-control" name="job_title" type="text" value="" id="job_title">
</div>
</div>
<div class="form-group">
<label for="company_phone_no" class="col-sm-4 control-label">Company telephone number<span class="required"> *</span></label>
<div class="col-sm-4">
<input class="form-control" name="company_phone_no" type="text" value="" id="company_phone_no">
</div>
</div>
<div class="form-group">
<label for="company_supervisor" class="col-sm-4 control-label">Name of Supervisor<span class="required"> *</span></label>
<div class="col-sm-4">
<input class="form-control" name="company_supervisor" type="text" value="" id="company_supervisor">
</div>
</div>
<div class="form-group">
<label for="job_duration" class="col-sm-4 control-label">How long have you been with this job?<span class="required"> *</span></label>
<div class="col-sm-4">
<select class="form-control" id="job_duration" name="job_duration"><option value="6" selected="selected">Less then 6 months</option><option value="12">6 months to 1 year</option><option value="24">1 year to 2 years</option><option value="36">2 years to 3 years</option><option value="37">More than 3 years</option></select>
</div>
</div>
</div>
<div class="form-group">
<label for="monthly_income" class="col-sm-4 control-label">What's your monthly net income?<span class="required"> *</span></label>
<div class="col-sm-4">
<input class="form-control" name="monthly_income" type="text" value="350000" id="monthly_income">
</div>
<div class="col-sm-4">
<label class="disclosure">Need to show proof of income</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-4"></div>
<div class="col-sm-4">
<input class="form-control" id="monthly_income_text" readonly="true" name="monthly_income_text" type="text" value="Trescientos cincuenta mil">
</div>
</div>
<div class="form-group">
<label for="proof_of_income" class="col-sm-4 control-label">Do you have proof of income?<span class="required"> *</span></label>
<div class="col-sm-4">
<select class="form-control" id="proof_of_income" name="proof_of_income"><option value="Select">Select</option><option value="Yes" selected="selected">Yes</option><option value="No">No</option><option value="Maybe">Maybe</option></select>
</div>
</div>
<div class="form-group">
<label for="bank_account" class="col-sm-4 control-label">Do you have bank account under your name?<span class="required"> *</span></label>
<div class="col-sm-4">
<select class="form-control" id="bank_account" name="bank_account"><option value="Select">Select</option><option value="Yes" selected="selected">Yes</option><option value="No">No</option><option value="Yes, but I don't remember the details">Yes, but don't remember details</option></select>
</div>
</div>
<input type="hidden" name="calculate_status" class="form-control" value="1" />
<div class="form-group">
<div class="col-sm-4 col-sm-offset-3">
<input class="btn btn-primary btn-lg" name="calculate" type="submit" value="How much can I borrow?">
</div>
</div>
</div>
</div>
<input name="temp_amount" type="hidden" value="30000.0000">
<input name="temp_duration" type="hidden" value="0">
<div class="panel panel-default loan_amt_duration">
<div class="panel-heading">
Find below the maximum you can borrow based on the information provided.
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-12">
<div class="col-sm-12">
<h3>
Amount
</h3>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="col-sm-10 mt-15">
<a class="amountSliderDecrease" href="#">
<span class="glyphicon glyphicon-minus mr-15"></span>
</a>
<input id="amount" name="amount" data-slider-id='amountSlider' data-slider-class="slider-long" type="text" data-slider-min="10000.00" data-slider-max="200000.00" data-slider-step="10000" data-slider-value="30000.0000"/>
<a class="amountSliderIncrease" href="#">
<span class="glyphicon glyphicon-plus ml-15"></span>
</a>
</div>
<div class="col-sm-2 mt-15">
<input id="amount-manual-loan" name="amount-manual" class="amount-manual text-center" min="10000.00" max="200000.00"/>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="col-sm-12">
<h3>
Loan Duration
</h3>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="col-sm-10 mt-15">
<a class="durationSliderDecrease" href="#">
<span class="glyphicon glyphicon-minus mr-15"></span>
</a>
<input id="duration" name="duration" data-slider-id='durationSlider' type="text" data-slider-min="0" data-slider-max="4" data-slider-step="1" data-slider-value="0"/>
<a class="durationSliderIncrease" href="#">
<span class="glyphicon glyphicon-plus ml-15"></span>
</a>
</div>
</div>
</div>
<div class="pt-40 col-sm-12">
<div class="row totals">
<div id="borrower-data-url" data-url="https://staging.tutasa.com.uy/borrower/repayment-calculate" class="hide"></div>
<div class="col-md-3 mb-25 selected-result">
<span id="borrow_amount">$U 30,000</span>
<span class="amt_label">Total Amount</span>
</div>
<div class="col-md-3 mb-25 selected-result">
<span class="borrow_quota_display">$U 6,171</span>
<span id="borrow_quota_label" class="amt_label">
6 Monthly Quotas of:<sup>*</sup>
</span>
</div>
<div class="col-md-3 mb-25 selected-result">
<span class="borrow_rate_display">30.84%</span>
<span class="amt_label">Interest Rate</span>
</div>
<div class="col-md-3 mb-25">
<button id="credit_score" onClick="void(0)" style="cursor:pointer;" class="btn btn-block btn-success btn-lg col-sm-12" name="review" type="submit" value="Proceed to credit scoring">Proceed to credit scoring</button>
<button id="credit_score" onClick="void(0)" style="cursor:pointer; margin-top:15px;" class="btn btn-block btn-primary btn-lg col-sm-12" name="back_to_income" type="submit" value="Back">Back</button>
</div>
<input name="borrow_quota" type="hidden" value="6171">
</div>
</div>
</div>
</div>
</form>
</div>
</div>
<p>*Representative APR <span id="borrow_rate" class="borrow_rate borrow_rate_display">30.84</span>%. Terms subject to market conditions.</p>
</div>
<script type="text/javascript">
$(document).ready(function(){
if(false){
$('input[name="calculate"]').click();
}
$('#monthly_income').inputmask('[999999999]', {"numericInput": true, "greedy": false, "placeholder": ""});
$('#monthly_income').on('keyup', _.debounce(function(){
monthlyIncomeText();
}, 1000));
_.each(['input[name="borrow_quota"]','#purpose','#education','#priority','#income_type','#company_name','#job_title','#company_phone_no','#company_supervisor','#job_duration','#businessman_org_name',
'#businessman_org_phone','#businessman_ref','#indep_prof_industry','#indep_prof_ref','#indep_prof_ref_phone','#retired_prev_employer_name','#allow_grantor','#unemp_prev_employer_name',
'#monthly_income','#proof_of_income','#bank_account','#repayment_likelihood','#calculate_status','#fast_track_code','#fast_track_code_status','#amount_payable_to'], function(input){
$(input).change(function(){
var data = {};
if($('#amount').val()) data[btoa('amount')] = btoa($('#amount').val());
if($('#duration').val()) data[btoa('duration')] = btoa($('#duration').val());
if($('#borrow_rate').text()) data[btoa('rate')] = btoa($('#borrow_rate').text());
if($('input[name="borrow_quota"]').val()) data[btoa('quota')] = btoa($('input[name="borrow_quota"]').val());
if($('input[name="borrow_quota"]').val()) data[btoa('total')] = btoa($('#duration').val() ? 0.5 * 12 * $('input[name="borrow_quota"]').val() : $('#duration').val() * $('input[name="borrow_quota"]').val());
if($('#education').val()) data[btoa('education')] = btoa($('#education').val());
if($('#priority').val()) data[btoa('priority')] = btoa($('#priority').val());
if($('#income_type').val()) data[btoa('income_type')] = btoa($('#income_type').val());
if($('#monthly_income').val()) data[btoa('monthly_income')] = btoa($('#monthly_income').val());
if($('#proof_of_income').val()) data[btoa('proof_of_income')] = btoa($('#proof_of_income').val());
if($('#proof_of_income').val()) data[btoa('proof_of_income')] = btoa($('#proof_of_income').val());
if($('#bank_account').val()) data[btoa('bank_account')] = btoa($('#bank_account').val());
if(input.indexOf('#') != -1){
data[btoa(input.replace('#', ''))] = btoa($(input).val());
}
data[btoa('user_id')] = btoa(49095);
data[btoa('type')] = btoa('borrower');
data['_token'] = $('form').find('input[name="_token"]').val();
$.ajax({
url: 'https://staging.tutasa.com.uy/loan/save-temp-loan',
data: data,
type: 'POST',
cache: false,
dataType: "json"
});
});
});
$('#fast_track_code_status').val('');
$('.fast_track_code_error').hide();
if($('#fast_track_code').val() != '') {
if($('#fast_track_code_apply').length > 0) {
$( "#fast_track_code_apply" ).trigger( "click" );
}
}
function showIncomeFields(){
$('.income-employee').addClass('hidden');
$('.income-businessman').addClass('hidden');
$('.income-independent-professional').addClass('hidden');
$('.income-retired').addClass('hidden');
$('.income-allowances').addClass('hidden');
$('.income-rent').addClass('hidden');
$('.income-unemployed').addClass('hidden');
$('.income-'+$('#income_type').val()).removeClass('hidden');
}
showIncomeFields();
$('#income_type').change(function(){
showIncomeFields();
});
function monthlyIncomeText(){
console.log($('#monthly_income').val());
if($('#monthly_income').length && $.isNumeric($('#monthly_income').val()) && $('#monthly_income').val() > 0){
var data = {};
data[btoa('number')] = btoa($('#monthly_income').val());
data['_token'] = $('form').find('input[name="_token"]').val();
$.ajax({
url: 'https://staging.tutasa.com.uy/borrower/numbers-to-words',
data: data,
type: 'POST',
cache: false,
dataType: "json",
success: function(data) {
console.log(data);
if (data.status === true) {
$('#monthly_income_text').val(data.text.substr(0,1).toUpperCase() + data.text.substr(1));
}else{
$('#monthly_income_text').val('');
}
},
error: function(error) {
console.log(error);
$('#monthly_income_text').val('');
}
});
}else{
$('#monthly_income_text').val('');
}
}
monthlyIncomeText();
});
</script>
</div>
</div>
</div>
<script src="https://staging.tutasa.com.uy/js/underscore-min.js"></script>
<script src="https://staging.tutasa.com.uy/js/pdf/build/pdf.js"></script>
<script src="https://staging.tutasa.com.uy/layouts/js/bootstrap.js"></script>
<script src="https://staging.tutasa.com.uy/layouts/js/bootstrap-datepicker.js"></script>
<script src="https://staging.tutasa.com.uy/layouts/js/angular.min.js"></script>
<script src="https://staging.tutasa.com.uy/js/bootbox.min.js"></script>
<script src="https://staging.tutasa.com.uy/layouts/js/bootstrap-slider.js"></script>
<script src="https://staging.tutasa.com.uy/layouts/js/heartcode-canvasloader-min.js"></script>
<script src="https://staging.tutasa.com.uy/js/inputmask/inputmask.js"></script>
<script src="https://staging.tutasa.com.uy/js/inputmask/jquery.inputmask.js"></script>
<script src="https://staging.tutasa.com.uy/js/inputmask/inputmask.numeric.extensions.js"></script>
<script src="https://staging.tutasa.com.uy/js/sliders.js?1512484810"></script>
<script src="https://staging.tutasa.com.uy/js/scripts.js?1512484810"></script>
</body>
</html>

curl command into Java - encoding xml file

I have what I believe is a simple curl command that I'm trying to turn into appropriate Java code, to put into my Java-based app. The curl command is like this:
curl -d command=setUserItem -d data_action=replace --data-urlencode user#user.xml --data-urlencode vfs_items#vfs_items.xml https://www.example.com/
Note it involves two xml flat files... When I invoke curl from the folder that contains those files... I get back a good response, that is an xml that has a few tags that lets me know it processed the command okay, and it creates a user as it should.
Below is my Java code. My feeling is that i'm not doing the part of handling the xml files's content correctly... I try just putting it into a string, but no luck. When I invoke through Java.... I get back a "bad" response indicating i'm not calling it correctly.
String xmlUser, xmlVfsItems, xmlPermissions;
String urlStr;
String[] paramName;
String[] paramVal;
xmlUser = "" +
" <?xml version=\"1.0\" encoding=\"UTF-8\"?> <user type=\"properties\"> " +
" <password>web</password> " +
" <version>1.0</version> " +
" <root_dir>/</root_dir> " +
" <userVersion>6</userVersion> " +
" </user> " +
"";
xmlVfsItems = "" +
"<?xml version=\"1.0\" encoding=\"UTF-8\"?> " +
"<vfs_items type=\"vector\"> " +
"<vfs_items_subitem type=\"properties\"> " +
"<name>curl_user</name> " +
"<path>/</path> " +
"<vfs_item type=\"vector\"> " +
"<vfs_item_subitem type=\"properties\"> " +
"<url>FILE://Users/ftp_accounts/curl_user/</url> " +
"</vfs_item_subitem> " +
"</vfs_item> " +
"</vfs_items_subitem> " +
"</vfs_items> " +
"";
urlStr = "https://www.example.com/";
paramName = ["command", "data_action","user", "vfs_items"];
paramVal = ["setUserItem", "replace", xmlUser, xmlVfsItems];
httpPost(urlStr, paramName, paramVal);
String httpPost(String urlStr, String[] paramName, String[] paramVal) throws Exception {
URL url = new URL(urlStr);
HttpURLConnection conn =
(HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setAllowUserInteraction(false);
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
// Create the form content
OutputStream out = conn.getOutputStream();
Writer writer = new OutputStreamWriter(out, "UTF-8");
for (int i = 0; i < paramName.length; i++) {
writer.write(paramName[i]);
writer.write("=");
writer.write(URLEncoder.encode(paramVal[i], "UTF-8"));
writer.write("&");
}
writer.close();
out.close();
if (conn.getResponseCode() != 200) {
throw new IOException(conn.getResponseMessage());
}
// Buffer the result into a string
BufferedReader rd = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
conn.disconnect();
println(sb.toString());
return sb.toString();
}
This is the good response I get from curl:
<?xml version="1.0" encoding="UTF-8"?>
<result><response_status>OK</response_status> <response_type>text</response_type>
<response_data></response_data></result>
The web-service involes creating a user within the CrushFTP system, and I can also verify the new user is created.
Here's the "bad response" I get from java... It looks like it is presenting the webpage as if I had accessed the url through a browser... the user-record it is suppose to create is not created:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>CrushFTP WebInterface</title> <link rel="stylesheet" type="text/css" href="/WebInterface/jQuery/css/login.css" /> <script type="text/javascript" src="/WebInterface/Resources/js/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="/WebInterface/jQuery/js/jquery-ui-1.8.2.custom.min.js"></script> <script type="text/javascript" src="/WebInterface/jQuery/js/jquery.blockUI.js"></script> <script type="text/javascript" src="/WebInterface/Resources/js/login.js"></script> <script type="text/javascript"> function showRecaptcha(element) { if(window.Recaptcha) { window.Recaptcha.create("/*RECAPTCHA_PUBLIC_KEY*/", element, { theme: "red" }); } } $(document).ready(function() { /*RECAPTCHA*/ }); var passwordRule = {random_password_length:6,min_password_numbers:0,min_password_lowers:0,min_password_uppers:0,min_password_specials:0}; </script> <script></script> </head> <body style="overflow-x: hidden; overflow-y: auto;" class="login"> <div id="login"> <div id="languageSelector" style="display:none;"> <select> <option value="en" rel="English">English</option> <option value="cn" rel="Chinese">Chinese</option> <option value="cs" rel="Czech">Czech</option> <option value="da" rel="Danish">Danish</option> <option value="nl" rel="Dutch">Dutch</option> <option value="fr" rel="French">French</option> <option value="de" rel="German">German</option> <option value="hu" rel="Hungarian">Hungarian</option> <option value="it" rel="Italian">Italian</option> <option value="pl" rel="Polish">Polish</option> <option value="sk" rel="Slovak">Slovak</option> <option value="es" rel="Spanish">Spanish</option> <option value="se" rel="Swedish">Swedish</option> </select> </div> <form id="loginForm" name="loginForm" method="post" action="/" onSubmit="return doLogin2();"> <div id="panelbody"> <div id="branding" class="clearfix branding"> <img id="loginWheel" src="/WebInterface/images/wheel.gif" /> <a id="defaultLogoLink" href="http://www.crushftp.com/"> <img id="imgLogo" src="/WebInterface/images/logo.png" style="border-width:0px;float:left;" /> </a> </div> <div id="panelLogin"> <div> <label id="UserNameText">Username</label> <input autocomplete="on" type="text" class="textbox" name="username" id="username" value="" /> </div> <div> <label id="PasswordText">Password</label> <input type="password" class="textbox" name="password" id="password" value="" /> </div> <div id="rememberMePanel"> <label><input type="checkbox" name="remember" id="remember" /> <span id="RememberMeText">Remember Me</span></label> </div> <div style="clear:both;height:1px;padding:0px;margin:0px;"></div> <div id="recaptcha_div"></div> <div style="clear:both;height:1px;padding:0px;margin:0px;"></div> <div class="submit clearfix"> <input type="submit" value="login" style='display:none;' /> <input type="hidden" name="command" value="login" /> <input type="hidden" name="skip_login" value="true" /> <input type="hidden" name="encoded" value="false" /> <input type="submit" value="login now" style="position:absolute;left:-1000px;top:-1000px;" /> <a class="button" id="btnLogin" href="javascript:void(0);"> <span id="LoginButtonText">Login</span> </a> </div> <p class="lostpassword"> I forgot my password, email it to me. </p> </div> </div> </form> <form id="changePassForm" method="post" target="dummyIframe" action="/WebInterface/function/" onSubmit="doLogin();"> <div id="changepasswordPanel" style="display:none;margin-bottom:10px;"> <div class="clearfix branding" style="clear:both;"> <a id="defaultLogoLink" href="http://www.crushftp.com/"> <img id="imgLogo" src="/WebInterface/images/logo.png" style="border-width:0px;float:left;margin:3px 0px 10px 0px;" /> </a> </div> <h2 class="popupHeader" style="clear:both;margin-top:15px;" id="ChangePasswordHeaderText"> Change your password </h2> <div class="passwordChangeNote" id="ChangePasswordNoteText"> You must change your password to continue </div> <div class="buttonPanel"> <label for="current_password" id="CurrentPasswordText">Current Password:</label> <input id="current_password" class="textbox" type="password" /> <br /> <br /> <label for="new_password1" id="NewPasswordText">New Password:</label> <input id="new_password1" class="textbox" type="password" /> <br /> <br /> <label for="new_password2" id="ConfirmPasswordText">Confirm Password:</label> <input id="new_password2" class="textbox" type="password" /> <div style="text-align:right;margin-top:10px;"> <a id="btnChangePasswordCancel" class="button" href="javascript:void(0);"> <span id="CancelButtonText">Cancel</span> </a> <a id="btnChangePassword" class="button" href="javascript:void(0);"> <span id="ChanngePasswordButtonText">Change Password</span> </a> </div> <div style="clear:both"></div> <div class="spacing"> <br /> <hr /> <br /> </div> <div> <a id="btnGeneratePassword" class="button" href="javascript:void(0);" style="float:left"> <span id="GeneratePasswordButtonText">Generate password</span> </a> <div id="passwordGeneratePanel" style="display:none;"> <br /> <br /> <input id="generated_password" type="text" class="textboxSmall" style="float:left;" /> <a id="usePassword" class="button" href="javascript:void(0);" style="float:left"> <span id="GeneratePasswordUseButtonText">Use this</span> </a> <a id="cancelPassword" class="button" href="javascript:void(0);" style="float:left"> <span id="GeneratePasswordCancelButtonText">Cancel</span> </a> </div> <div style="clear:both"></div> </div> </div> </div> </form> </div> <div id="OTPBox" style="display:none;"> <img class="closeButton" alt="close" src="/WebInterface/jQuery/images/cancel.png" onclick="$.unblockUI();"/> <h2 class="popupHeader" id="OTPDialogHeaderText"> Enter your OTP here </h2> <div class="buttonPanel"> <div style="width:100%;"> <input id="otp" type="password" style="width:95%;padding:5px;" /> </div> <br /> <br /> <div style="text-align: right; margin-top: 10px;"> <button id="btnSubmitOTP"> <span id="OTPSubmitButtonText">Submit</span> </button> </div> </div> </div> <div id="olderBrowserNotice" style="display:none;top:100px;padding: 10px;" class="alertMessage"> <div id="OldBrowserNoticeHTMLAsText"> Your browser is out of date, it was released almost a decade ago! As a result it is very slow, full of bugs, and this WebInterface may or may not even work with IE6. <br /> <br /> <div style="text-align:right;"> <button id="proceedAnyway">Proceed Anyway Cautiously</button>or get a better browser : Chrome | FireFox </div> </div> </div> <iframe id="dummyIframe" name="dummyIframe" src="javascript:false;" style="display:none;"></iframe> </body></html>
I "dumbed down" the question to post it here, and I mistakenly omitted a key part... The part that was actually causing my problem... The URL also had a username/password, which I needed to turn into a Authorization: header with the credentials BASE64 encoded.
Thanks all for responding... the mention about the header got me thinking about it.

HTTP Status 405 - Request method 'GET' not supported

I want to add payments to my clients database but when I add the payments I got this error "GET NOT SUPPORTED" I don't know what's the problem. Can you guys help me?
#Controller
public class PaymentsController {
#Autowired
private UsersService usersService;
#Autowired
private PaymentsService paymentsService;
#RequestMapping(value = "/addPayments", method = RequestMethod.POST)
public String addPayments(HttpServletRequest request, ModelMap map) {
String user = request.getParameter("userId"); // this is the identifier for the user of this payment
String transactName = request.getParameter("transactName");
String paid = request.getParameter("paid");
String unpaid = request.getParameter("unpaid");
String balance = request.getParameter("balance");
String total = request.getParameter("total");
//.... get all other attributes you've passed from the form through request.getParameter("");
//next, check whether or not a user with the userId from the screen exists in the db
Users userObject = usersService.getUsers(user);
//.getUsersByUserId(user);
if (userObject != null) {
// this means that we have a valid user to insert the payment to
UsersPayments payment = new UsersPayments();
payment.setUsers(userObject);
payment.setTransactName(transactName);
payment.setPaid(paid);
payment.setUnpaid(unpaid);
payment.setBalance(balance);
payment.setTotal(total);
//.... set the other properties of UsersPayment object
paymentsService.addPayments(payment);
}
else {
// you have an error right here
}
map.put("paymentsList", paymentsService.getAllPayments());
return "payments";
}
}
payments.jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# include file="/WEB-INF/jsp/includes.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="<c:url value="/resources/css/design.css" />" rel="stylesheet">
<link href="<c:url value="/resources/css/customized.css" />" rel="stylesheet">
<link href="<c:url value="/resources/css/bootstrap.css" />" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Canadian Immigration Consultancy</title>
</head>
<body>
<div id="wrapper">
<div id="logo">
<img src="<c:url value="/resources/images/logo4.png" />" height="200px" width="230px"/>
<img src="<c:url value="/resources/images/header06.jpg" />" height="200px" width="765px"/>
</div>
<div class="red">
<div align="center" id="slatenav">
<ul>
<li>Home</li>
<li>View All</li>
<li>Reports</li>
<li>Add Leads</li>
<li><spring:message code="user.logout"/></li>
</ul>
</div>
</div>
<div id="balance" >
<form action="addPayments" method="POST">
<div class="well well-sm box16">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Payments</h3>
</div>
<div class="panel-body">
<div class="form-group">
<br><div class="col-sm-2 control-label">Transaction Name</div>
<div class="col-sm-10">
<input type="text" class="form-control" name="transactName" autofocus />
</div>
</div>
<div class="form-group">
<br><div class="col-sm-2 control-label">Amount Paid</div>
<div class="col-sm-10">
<input type="text" class="form-control" name="paid" />
</div>
</div>
<div class="form-group">
<br><div class="col-sm-2 control-label">Unpaid</div>
<div class="col-sm-10">
<input type="text" class="form-control" name="unpaid" />
</div>
</div>
<div class="form-group">
<br><div class="col-sm-2 control-label">Total Balance</div>
<div class="col-sm-10">
<input type="text" class="form-control" name="balance" />
</div>
</div>
<div class="form-group">
<br><div class="col-sm-2 control-label">Total Amount</div>
<div class="col-sm-10">
<input type="text" class="form-control" name="total" />
</div>
</div>
<div class="save">
<input type="submit" class="btn btn-success" value="Save" />
</div>
</form>
</div>
</div>
</div>
</body>
</html>
You only seem to have one handler mapping, and it's POST. Add another handler mapping for the same url path with GET. Consider the "POST Redirect GET" pattern as well.

Categories

Resources