HTTP Status 404 – Not Found Tomcat - eclipse

This is my code. I'm trying to add values to my table using JSP and MYSQL. Name of the table and database is correct.
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# page import ="java.sql.*" %>
<%# page import ="javax.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Inserting Data from form</title>
</head>
<body>
<h1> Insert a Record</h1>
<form method="post" action="insertrecord.jsp">
<table>
<tr>
<td>
<input type="text" name="uname">
</td>
<td>
<input type="password" name="upass">
</td>
<tr>
<tr>
<td><input type="submit" name="submit" value ="submit"></td>
</tr>
</table>
</form>
<%
String sub = request.getParameter("submit");
if(sub!=null)
{
String uname=request.getParameter("uname");
String password = request.getParameter("upass");
if(uname!=null && password!=null)
{
try
{
Connection con;
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/demo","root","");
Statement stmt = con.createStatement();
int i = stmt.executeUpdate("insert into user values ('"+uname+"','"+password+"')");
out.println("Record Inserted Successfully");
stmt.close();
con.close();
}
catch(SQLException e)
{
out.println(e.getMessage());
}
}
}
%>
</body>
</html>
When I click on submit. I'm getting this error:
HTTP Status 404 – Not Found
Type Status Report
Message /something/insertrecord.jsp
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/9.0.5

Related

codeigniter sending email with logo not working

I'm using CI version 3 and I'm using the built in email functionality to send an HTML email template.
My code is as following:
public function send_email($sendTo, $fromName, $fromEmail, $data, $subject) {
$this->email->set_mailtype('html');
$this->email->from($fromEmail, $fromName);
$this->email->to($sendTo);
$this->email->subject($subject);
$this->email->attach(FCPATH . "images/logo.png", "inline");
$content = array(
'HTMLcontent' => $data
);
$body = $this->load->view('email_template.php', $content, TRUE);
$this->email->message($body);
if ($this->email->send()) {
return TRUE;
} else {
return FALSE;
}
}
The FCPATH is ok it shows : /home/myuser/public_html/ and I have images folder inside public_html
email_template.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<table>
<tr>
<td>
<a href="" target="_blank">
<img src="cid:logo.png" width="144" height="76" border="0" alt="logo"/>
</a>
</td>
</tr>
</table>
</body>
</html>
When the email comes it shows with a missing logo as the image below

form not able to pass parameter into requestparam when using rest services

I am trying to send some values from a form to a responsebody for doing some actions on those values. But the values are not at all getting forwarded to that handler. i couldn't find a reason.
What could be the problem here?
My handler
#RequestMapping(value="/redemptionRedirect1/{userId}", method=RequestMethod.GET)
#ResponseBody
public Transaction submitRedemption(#PathVariable("userId") long userId,#RequestParam(value="amount") String amount1,#RequestParam("bankaccount") int bankaccount,#RequestParam("demataccount") int demataccount)
{
boolean flag;
Double amount=Double.parseDouble(amount1);
Transaction transaction=new Transaction();
transaction.setBankAccount(transactionService.getBank(bankaccount));
transaction.setDematAccount(transactionService.getDemat(demataccount));
transaction.setTransactionAmount(amount);
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String name = auth.getName();
User user=userService.getUser(name);
transaction.setUser(user);
flag = transactionService.addRedemptionTransactions(transaction);
return transaction;
}
My JSP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="redemptionRedirect1/${user.userId}.htm" method="get">
<table>
<tr><td>Amount: </td><td><input id="amount" type="text" maxlength="5" value='<c:out value="${amount}"/>' placeholder='<c:out value="${amount}"/>'/></td></tr>
<tr><td>
Bank Accounts: </td><td><select id="bankaccount" >
<c:forEach items="${baccounts}" var="account">
<option value='<c:out value="${account.accountNumber}"/>'>
<c:out value="${account.name}"/>
</option>
</c:forEach>
</select>
</td></tr>
<tr><td>Demat Account: </td><td><input id="demataccount" type="text" placeholder='<c:out value="${daccount.dematName}"/>' value='<c:out value="${daccount.dematAccountNumber}"/>'/></td></tr>
<tr><td><input type="submit" value="Confirm"/></td></tr>
</table>
</form>
</body>
</html>
The form serializes itself via name attribute of every input.
So first you may run the developer tools feature of your browser and check if the values are added to the request or (this works only for GET requests) check if the values are added to the URL after the submit. If not - add the name attribute for every corresponding input.

jsp form selection not working

I have following jsp page, when i select MYAP_FORM i expect the hidden form to be displayed but it is not.
Right now i have only one form with display none, i will be adding more and based on the selection will display right one.
Any inputs why i dont see the corresponding form displayed ...
Thanks
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# page import="java.io.*"%>
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%#taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="url">${pageContext.request.requestURL}</c:set>
<c:set var="baseURL" value="${fn:replace(url, pageContext.request.requestURI, pageContext.request.contextPath)}" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="${baseURL}/bootstrap/css/bootstrap.css">
<title>Testing</title>
</head>
<body>
<script src="${baseURL}/bootstrap/js/bootstrap.js"></script>
<form id="platform" class="container text-center">
<select id="myselect">
<option value="" selected="selected"></option>
<option value="MYAP_FORM">MYAP_FORM</option>
<option value="XYZ_FORM">XYZ_FORM</option>
</select>
</form>
<%
String file = application.getRealPath("/") + "xzyFiles.txt";
FileInputStream fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String tmp;
out.println("<form class=\"container\" id=\"MYAP_FORM\" style=\"display:none\">");
while ((tmp = br.readLine()) != null) {
out.print("<label class=\"checkbox text-left\">");
out.print("<input type=\"checkbox\" id=\"" + tmp +"\" value=\"1\">" + tmp + "</BR>");
out.print("</label>");
}
fis.close();
out.println("<button class=\"btn btn-primary\">Submit</button>");
out.println("<button class=\"btn btn-primary\">Clear</button>");
out.println("</form>");
%>
<script>
$("#myselect").on("change", function() {
$("#" + $(this).val()).show();
})
</script>
</body>
</html>
JQuery Script was missing, once added it worked fine.

Spring 3 MVC Form not saving data in database

I am trying to run a simple Spring 3 MVC project to save form data but when I submit data the page goes to add.html with empty forms and no data is save in Mysql neither it is shown on the page.
Controller
package com.app.a;
/**
* Handles requests for the application home page.
*/
#Controller
#RequestMapping(value="/")
public class HomeController {
#Autowired
private Personrepo personRepo;
#RequestMapping(method=RequestMethod.GET)
public String showForm(ModelMap model){
List<Person> persons = personRepo.getAll();
model.addAttribute("persons", persons);
Person person = new Person();
person.setId(UUID.randomUUID().toString());
model.addAttribute("person", person);
return "home";
}
#RequestMapping(value="/add", method=RequestMethod.POST)
public ModelAndView add(#ModelAttribute(value="person") Person person,BindingResult result){
ModelAndView mv = new ModelAndView("home");
if(!result.hasErrors()) {
personRepo.add(person);
person = new Person();
person.setId(UUID.randomUUID().toString());
mv.addObject("person", person);
}
mv.addObject("persons", personRepo.getAll());
return mv;
}
#RequestMapping(value="/edit", method=RequestMethod.POST)
public ModelAndView edit(#ModelAttribute(value="person") Person person,BindingResult result) {
ModelAndView mv = new ModelAndView("home");
if(!result.hasErrors()) {
personRepo.edit(person);
person = new Person();
mv.addObject("person", person);
}
mv.addObject("persons", personRepo.getAll());
return mv;
}
#RequestMapping(value="/delete", method=RequestMethod.POST)
public ModelAndView update(#ModelAttribute(value="person") Person person,BindingResult result){
ModelAndView mv = new ModelAndView("home");
if(!result.hasErrors()) {
personRepo.delete(person.getId());
//personRepo.delete(person);
person = new Person();
mv.addObject("person", person);
}
mv.addObject("persons", personRepo.getAll());
return mv;
}
}
Home .jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%#taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<table align="center">
<c:forEach items="${persons}" var="person">
<tr>
<td>Welcome:</td>
<td><c:out value="${person.firstName}" /></td>
</tr>
<tr>
<td>Your lastname:</td>
<td><c:out value="${person.lastName}" /></td>
</tr>
</c:forEach>
</table>
<form:form modelAttribute="person" method="post" action="add.html">
<form:hidden path="id" />
<table>
<tr>
<td><form:label path="firstName">First Name:</form:label></td>
<td><form:input path="firstName" /></td>
</tr>
<tr>
<td><form:label path="lastName">Last Name</form:label></td>
<td><form:input path="lastName" /></td>
</tr>
<tr>
<td><form:label path="money">Money</form:label></td>
<td><form:input path="money" /></td>
</tr>
</table>
<input type="submit" value="Save" />
</form:form>
</body>
</html>
From the looks of it, unless you are doing content negotiation, you don't have a controller method mapped to the URL add.html.
Compare:
<form:form modelAttribute="person" method="post" action="add.html">
and
#RequestMapping(value="/add", method=RequestMethod.POST)
Make it
<form:form modelAttribute="person" method="post" action="add">
and you should be fine.

GWT getAbsoluteLeft/Top returns wrong value in FF

when i call the getAbsoluteLeft/Top method i always get 0 in firefox. For the IE i get a value which seems to be correct. Are there known problems using these methods ? My problem is that i want to set the position of an element with the absolute position values of another element. Thanks in advance. Edit: Using GWT 2.0.3
kuku
EDIT Testcase:
1. The host page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Web Application Starter Project</title>
<script type="text/javascript" language="javascript" src="samplegwt/samplegwt.nocache.js"></script>
<script type="text/javascript" language="javascript">
function execute() {
var element = document.getElementById("paragraph");
if (element != undefined)
element.style.display = "block";
}
</script>
<STYLE TYPE="text/css">
#paragraph {
display: none;
}
</STYLE>
</head>
<body class="body" onload="execute()">
<div align="center">
<table>
<tr>
<td>
<p id="paragraph">
<input type="text" id="example" value="Foobar" > <img border="0" src="images/some.gif" alt="Test"></p>
</td>
</tr>
</table>
</div>
</body>
</html>
In the onModuleLoad() i simply do this: System.out.println(Document.get().getElementById("paragraph")
.getAbsoluteLeft());
Well as stated in the comments the problem was that the element is not visible which results into 2 different behavoirs for IE and FF.