Home>
Nice to meet you.
I am currently learning Java.
I am currently trying to implement a login function.
However, I don't quite understand the description of the servlet for passing the user ID and password information received from JSP to DAO.
// Servlet initialization parameter information
String userid = request.getParameter("loginid");
String password = request.getParameter("userpassword");
What kind of description should I make in order to pass the information received in to DAO?
If i know anything about how to describe it, I would appreciate it if you could teach me.
I am still learning, and honestly I don't know much. Therefore, corrections to the questions are also welcome.
Thank you very much.
<%@ page language="java" contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8"%><%@ page import="common.LoggerTester" %><% request.setCharacterEncoding("UTF-8");%><% String loginErrorMessage = (String)request.getAttribute("loginErrorMessage");%><html><head> <meta charset="UTF-8"> <title>Book management system-<Login></title> <link rel="stylesheet" href="header.css"></head><header><p>Login to book management system</p><hr></header><body> <table border="0"> Used to create a blank. It does not appear on the screen. Used to create a blank. It does not appear on the screen. <%
LoggerTester lt = new LoggerTester();
lt.outActionLog("login.jsp", "start processing");
%> <% if(loginErrorMessage != null){ %> <center><p><%= loginErrorMessage %></p></center> <%} %> Used to create a blank. It does not appear on the screen. <form method="POST" action="Login"> <p>User ID<br> <input type="text" name="loginid" value="" size="24"> <p>Password<br> <input type="password" name="userpassword" value="" size="24"> <br> <input type="submit" value="login"> </form> </table> </body></html>
package exam;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import dao.UserDAO;
@WebServlet("/Login")
public class LoginServ extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//Start session by getSession method
HttpSession session = request.getSession();
//Specify the character string encoding method received in the request
request.setCharacterEncoding("UTF-8");
LoggerTester lt = new LoggerTester();
lt.outActionLog("Login", "Start processing");
try {
// Servlet initialization parameter information
String userid = request.getParameter("loginid");
String password = request.getParameter("userpassword");
//Get login data from UserDAO
UserDAO dao = new UserDAO();
User user = dao.selectUser(loginid, userpassword);
//if (request.getParameter("username") == un){
if (user != null) {
session.setAtribute("user", user);
getServletContext().getRequestDispatcher("/BookManagementListDisp.java").forward(request, response);
}else {
request.setAttribute("loginErrorMessage","The input is incorrect.");
getServletContext().getRequestDispatcher("/login.jsp").forward(request, response);
}
// In case of DB error, register error message in request and forward to login screen
}catch(Exception e){
e.printStackTrace();
request.setAttribute("dbConnectionError", "There was an error with the database connection.");getServletContext().getRequestDispatcher("/errorMessage.jsp").forward(request, response);
}
}
}
package dao;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.ArrayList;
public class UserDAO implements Serializable {
// accessor method
private String _loginid;
private String _userpassword;
private int _admin;
private String _name;
public void setloginid(String loginid) {
this._loginid = loginid;
}
public String getloginid() {
return this._loginid;
}
public void setuserpassword(String userpassword) {
this._userpassword = userpassword;
}
public String getuserpassword() {
return this._userpassword;
}
public void setadmin(int admin) {
this._admin = admin;
}
public int getadmin() {
return this._admin;
}
public void setname(String name) {
this._userpassword = name;
}
public String getname() {
return this._name;
}
// Get all the data registered in the table
// Get the set information
public UserDAO selectUser(String loginid, String userpassword)
Throws ClassNotFoundException, SQLException{
UserDAO user = new UserDAO();
// 1 user information
UserDAO info = new UserDAO();
info.setloginid("000014");
info.setuserpassword("aiueo");
info.setadmin(0);
info.setname("aiueo");
// set return value
return UserList;
}
}
-
Answer # 1
Related articles
- ruby - i want to search for form information in rails and save the result
- java - i cannot log in with the registered user information
- java - i want to extract the information acquired from dto from the left three characters and set it in an application variable
- java - about fuzzy search function of spring boot
- java - i get an error when trying to get information from the zip url that actually exists (multiple text files in zip)
- java - what is the form to hold the processing to get the search result in arraylist?
- java - i want to display the content received from other servlets with a label on the jsp and register the content displayed on
- java - about generics of binary search
- java - calculate the average value of the student information class that manages multiple students
- java - search multiple items about how to write findby 〇 and △ like()
- java - displaying database search results using a form configured with jsp/servlet
- java - the information acquired by dao is not output as a log even though the login is successful
- java - the information set in dao cannot be linked to servlet, and the value will be null
- a program that generates a password when you press the button java swing
- java - "gas" i want to reflect the information of the error mail that returns to gmail in the spreadsheet
- java - image information cannot be acquired
- java - i want to store the information obtained from dto in the dto type of arraylist
- java - i want to perform fuzzy search using bind variables
- java - information registered in sqlite is sorted and displayed in ascending order using arrayadapter (arraylist)
Related questions
- java : When the value obtained from ArrayList is displayed on the screen with jsp, unnecessary square brackets ("[", "]") are ou
- java : How to set the passed object in jsp form
- java : An error occurs while initializing the Servlet class
- java : SpringMVC request encoding issues
- java : How to pass parameter from one controller method to another
- java : Transition not firing after Spring Security authorization
- javascript : Reload page on JS form submit
- java : Pass parameter to controller from form
- java : How to pass var Jsp value to Controller Spring
- Login with Java
Ahh. I finally understood.
Please match the information on the DAO side (stub) instead of getting the information from DAO.