I have a simple html form (first name and last name) once I hit submit it should give me a simple response from my java servlet that says "Hello plus first name plus last name"
I ran this using eclipse and a tomcat plugin and it works perfectly.. but when I create a war file and deploy it from tomcat.. I get the first screen.. enter first and last name.. but when I hit submit, it looks for "WelcomeScreen" nowhere in my code do i have "welcomeScreen" Below is my HTML code.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Please enter your name</title>
</head>
<body>
<form name="input" action=Hello method="get">
First name: <input type="text" name="firstname"><br> Last
name: <input type="text" name="lastname"> <input type="submit"
value="Submit">
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Please enter your name</title>
</head>
<body>
<form name="input" action="Hello.html" method="get">
First name: <input type="text" name="firstname" /><br>
Last name: <input type="text" name="lastname" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
I wrote correct code. There were some mistakes in html like;
<form name="input" action=Hello method="get">
<!-- You've forgotten quotes -->
<!-- And also dont forget to write ".html" or Hello controller in framework like MVC -->
<form name="input" action="Hello.html" method="get">
Another one
<input type="text" name="firstname">
<!-- You've forgotten /// -->
<input type="text" name="firstname" />
And your Hello.html
<html>
<head>
<title>Title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<script type="text/javascript">
var get = window.location.search.replace( "?", "" );
alert(get);
</script>
</head>
<body>
<div>Content</div>
</body>
</html>
Related
It was working fine but suddenly its now working for ${message} and others as ${param.someName}
this is my .java class
#PostMapping("/validate")
//All the libraries are also imported and no error in code
String validateLogin(String mail,String password,String location,HttpSession session,HttpServletRequest req,Model model) {
User user;
//user=urepo.findByEmail(mail);
user=urepo.findByEmailAndPassword(mail,password);
if(user!=null)
{
req.getSession();
session.setAttribute("userid", user);
System.out.println(location);
System.out.println(user.getFname());
return "redirect:/"+location;//+"?session=userid";
}
model.addAttribute("message", "please check the username/password");
//req.setAttribute("message", "Please check the username or password");
return "redirect:login?location="+location;
}
below is my .jsp login form when I'm entering wrong password on the jsp page I want to display the message which is written in the above java file but its not displaying the ${message} and also not working with the ${param.email} too but login is working fine
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Login</title>
//Bootstrap link
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
</head>
<body>
<div class="container-md text-center">
<div class="row mx-auto pt-5">
<h1>Welcome to Ekart...</h1>
<h3><i>Login please!!</i></h3>
<form action="validate" method="post">
<div class="col-md-5 col-sm mx-auto pt-2 pb-2">
<span>${message}</span>
UserName: <input type="email" name="mail" placeholder="email" value="${param.mail}">
</div>
<input type="hidden" name="location" value="${param.location}">
<!-- ${param.location} -->
<div>
<div class="col-md-5 col-sm mx-auto pt-2 pb-2">
Password: <input type="password" name="password" placeholder="password">
<br>
</div>
<input type="submit" class="btn btn-primary" value="login">
</form>
<br><br>
Create a Account?
</div>
</div>
</form>
</div>
</body>
</html>
<html lang="en">
<head>
<title>File Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form method="POST" action="upload" enctype="multipart/form-data" >
File:
<input type="file" name="file" id="file" /> <br/>
Destination:
<input type="text" value="/tmp" name="destination"/>
</br>
<input type="submit" value="Upload" name="upload" id="upload" />
</form>
</body>
I want to get all file path which is chosen via browser(input type="file") to upload it to ftp server.
I had found a lot of code snaps but just they give me file name I need absolute path such as "c:\users\filename".
Thank yo for your time.
For security reason, browsers do not provide you full/absolute path for any file.
hi mate i have in my folder a lot of file html equal( the only difference is the string).
i want in every file html of my folder delete a tag.
an example of my file html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>P0001 Generic DTC: Fuel Volume Regulator Control Circuit/Open</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="P0001 diagnostic trouble code details." />
<meta name="keywords" content="P0001, obd code, obd codes, diagnostic codes, trouble codes, diagnostic trouble codes, ford, gm, toyota, chrysler, dodge, nissan, chevy, dtc, dtcs, engine code, engine codes, check engine light" />
<link rel="stylesheet" type="text/css" href="/static/css/base.css"/>
<link rel="shortcut icon" href="/static/img/favicon.ico" />
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1196991-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body class="results one">
<div id="main">
<div id="header">
<div id="logo">DTCSearch.com</div>
<form action="/" method="post">
<p>
<input type="text" id="query" name="query" value="P0001"/>
<input type="submit" id="submit" value=""/>
</p>
</form>
</div>
<div id="content">
<h1>P0001 OBD Trouble Code</h1>
<p>1 result found</p>
<div id="content-body">
<table cellspacing="0" class="one">
<caption>P0001 - Generic</caption>
<tr>
<th>Type</th>
<td>Powertrain - Fuel and Air Metering - ISO/SAE Controlled</td>
</tr>
<tr>
<th>Description</th>
<td><p>Fuel Volume Regulator Control Circuit/Open</p></td>
</tr>
</table>
<p style="font-weight:bold">Try also: http://www.obd-codes.com/p0001</p>
</div>
</div>
<div id="footer">
<div id="footer_banner">
<img src="http://affiliates.eautorepair.net/42/65/15/&dp=84" alt="Do it Yourself Automobile Repair Information" border="0">
</div>
<p>Copyright © 2008–2012 DTCSearch.com<br/>
DTCSearch.com is hosted by ScanTool.net, LLC</p>
</div>
</div>
</body>
</html>`
i want to delete in every file this tag:
<img src="http://affiliates.eautorepair.net/42/65/15/&dp=84" alt="Do it Yourself Automobile Repair Information" border="0">
how do this ? tell me a solution with java or with bash or whit other tecnology.
You can use sed to delete a line from a file.
For example, the command:
sed '/foo/d' myfile
will delete all lines containing the word foo from myfile.
If you have multiple files you can run:
sed -i '/foo/d' *.html
The -i option tells sed to edit the files in-place.
i used:
sed -i 's#<img src="http://affiliates.eautorepair.net/42/65/15/&dp=84" alt="Do it Yourself Automobile Repair Information" border="0">##g' *
now i have a problem more serious. i want to delete
<p>
<input type="text" id="query" name="query" value="XXXXX"/>
<input type="submit" id="submit" value=""/>
</p>
where xxxxx are 5 character different in every file . how can do ?
I'm starting from here :
With that code :
<!DOCTYPE html>
<html>
<head><title>Bank application</title>
<link rel="stylesheet"
href="./css/styles.css"
type="text/css"/>
</head>
<body>
<table class="title">
<tr><th>Web Bank application</th></tr>
</table>
<br/>
<fieldset>
<legend>Login Page - please enter your Username and Password</legend>
<form action="loginPage">
Username: <input type="text" name="username"><br>
Password : <input type="text" name="password"><br>
<input type="submit" value="Login">
</form>
</fieldset>
<br/>
<br/>
<br/>
<fieldset>
<legend>Registration</legend>
<form action="register">
First name: <input type="text" name="firstName"><br>
Last name : <input type="text" name="lastName"><br>
Address : <input type="text" name="address"><br>
ID-number : <input type="text" name="idnumber"><br>
User-Name : <input type="text" name="userName"><br>
Password : <input type="text" name="password"><br>
<input type="submit" value="Register">
</form>
</fieldset>
<br/>
<br/><br/><br/><br/><br/><br/>
</body></html>
And while I move from one page to another , I reach here :
With that code :
<!DOCTYPE html>
<html>
<head><title>Authentication failed - a problem has occurred!</title>
<link rel="stylesheet"
href="./css/styles.css"
type="text/css"/>
</head>
<body>
<h1>Sorry , but you are not registered to our bank!</h1>
<fieldset>
<legend>Please press here to continue</legend>
<form action="goingBack">
<input type="submit" value="Press here">
</form>
</fieldset>
</body></html>
And I want to go back to index.html - the first page that I see when the program starts (the first picture above) .
How can I do that ? how can I forward back to index.html ?
Regards
Just add a link to the previous page in the last HTML:
<!DOCTYPE html>
<html>
<head><title>Authentication failed - a problem has occurred!</title>
<link rel="stylesheet"
href="./css/styles.css"
type="text/css"/>
</head>
<body>
<h1>Sorry , but you are not registered to our bank!</h1>
<fieldset>
<legend>Please press here to continue</legend>
<form action="goingBack">
<input type="submit" value="Press here">
</form>
</fieldset>
Go Back <!-- add this -->
</body></html>
You just need javascript. To redirect to /index.html after 5 seconds :
setTimeout('window.location='index.html';', 5000);
setTimeout() is a javascript function that sets a timer to trigger somehting after a given period of time. window.location is a variable that allows you to change the URL of the current page (thus redireting).
I'm trying to create a form that updates an entry in a MySQL database. The table is a users table that contains various fields related to the user. I need this page to work as an update form that takes a username that is passed to it via the previous page and pre-fills the text fields with the existing data. It's a model one application that uses a presentation, transport, and data layer. The transport layer is User.java and the data layer (that interacts with the database) is UserDB.java.
Here's the code, everything is functional except the pre-filling.
UPDATE: I've edited to reflect the changes from the answers below, I also want to note that "UserDB.getUsers()" returns an ArrayList.
<%# page language="java" contentType="text/html; charset=iso-8859-1"
pageEncoding="ISO-8859-1" import="java.util.ArrayList,beans.*,data.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
//get parameters from the request
String userName = request.getParameter("userName");
ArrayList userList = UserDB.getUsers(userName);
User user = userList.get(0);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="styles/style.css" type="text/css" />
<title>User Admin</title>
</head>
<body>
<div id="main">
<h1>Update User</h1>
<h3>User Info</h3>
<hr>
<div id="content">
<form action="updateUser.jsp" method="get">
<p>User Name<br>
<input type="text" name="userName" size="20" value="<%=userName%>"/>
</p>
<p>Password<br>
<input type="text" name="password" size="20" value="<%=user.getPassword()%>"/>
</p>
<p>First Name<br>
<input type="text" name="firstName" size="20" value="<%=user.getFirstName()%>"/>
</p>
<p>Last Name<br>
<input type="text" name="lastName" size="20" value="<%=user.getLastName()%>"/>
</p>
<p>Email Address<br>
<input type="text" name="email" size="20" value="<%=user.getEmail()%>"/>
</p>
<p>
<input type="submit" value="Commit Update">
</p>
</form>
</div>
</div>
</body>
</html>
I know I'm doing something wrong with the "user" object, but I'm overlooking it.
you are passing the username as a string
<%
//get parameters from the request
String userName = request.getParameter("userName");
user = UserDB.getUsers("userName");
//it should be (with out the quotes
user = UserDB.getUsers(userName);
%>
The "username" should have the quotes removed. Also, where are you declaring user's type?
ie.
User user = ....getUser..