Monday, April 13, 2020
Web Application
After a long time, I got chance to design a web application:
Dynamic web application, using JSP and Servlet
-Download Java (JDK and JRE) and install
-Download Eclipse IDE and install
-Download Tomcat and install
-Download MySql and install
- File - Download - Dynamic Web Project
Give Project Name-(Next)-src-(Next)-Click on web.xml (deployment descriptor)
web.xml: (file would be like this
WebApp1
login.jsp
Login
LoginServlet
LoginServlet
/login/*
- login.jsp
-loginBean.jsp
Class:
1- LoginBean
public class LoginBean {
String userName="";
String password="";
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}2- LoginServlet
import javax.servlet.annotation.WebServlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import java.sql.*;
/**
* Servlet implementation class Login
*/
@WebServlet("/Login")
public class Login extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Login() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Server at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//doGet(request, response);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String username=request.getParameter("username").toString();
String userpass=request.getParameter("password").toString();
HttpSession session = request.getSession(true);
if(username.equalsIgnoreCase(userpass))
{
response.sendRedirect("welcome.jsp");
}
else
{
response.sendRedirect("login.jsp");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
- Select Project-Run on Server
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment