AIM:
Write a Servlet that take First_ Name & Last_ Name from the user &
generate login-id such that two characters are from First_ Name & four
characters are from Last_ Name. Display the generated login-id.
Login.html:
<html>
<head>
<title>LoginForm
</title>
<meta
http-equiv="Content-Type" content="text/html;
charset=UTF-8">
</head>
<body>
<form
action="Welcome" method="post">
First
Name:<input type="textbox" name="fn"><br/>
Last
Name:<input type="textbox" name="ln"> <br/>
<input type="Submit"
value="Submit">
</form>
</body>
</html>
Welcome.java:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Welcome extends HttpServlet
{
protected
void doPost(HttpServletRequest request, HttpServletResponse response)
throws
ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String
fn = request.getParameter("fn");
String
ln = request.getParameter("ln");
int i
= ln.length();
String
a = fn.substring(0, 2);
String
b = ln.substring(i-4, i);
String
c = a+b;
out.println("Login id is:" +c);
}
}
Output:
No comments:
Post a Comment