Я только начал изучать JSP, и я столкнулся с определенной проблемой.я пытался предварительно заполнить мой HTML-код, получая электронную почту из базы данных.Сотрудник должен ввести свой идентификатор сотрудника, и в зависимости от идентификатора сотрудника электронное письмо отправляется в форму
Я пытался отправить идентификатор сотрудника с помощью jstl, но мне не удавалось, я всегда получаю сообщение об ошибке, сообщая идентификатор сотрудникаимеет значение null, может быть, я не понимаю логику отправки идентификатора сотрудника с помощью сервлетов или jstl
user-registration.jsp
<div class="regtop">
<h2>User Registration</h2>
</div>
<!-- <form action="RegisterControllerServlet"> -->
<c:url var="templink" value="RegisterControllerServlet">
<c:param name="command" value="LOAD"/>
</c:url>
<div class="container">
<p>Please fill in this form to create an account.</p>
<hr>
<label for="email"><b>Enter employee id</b></label>
<input type="text" name="u_eid" >
<a href="${templink}" >Get email</a>
<br>
<label for="email"><b>Email</b></label>
<input type="text" name="email" value="${THE_USER.email}">
RegisterControllerServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
//read the "command" parameter
String theCommand=request.getParameter("command");
//if the command is missing,then default to listing pharmacists
//route to the appropriate method
switch(theCommand)
{
case "LOAD":
loadUser(request,response);
break;
}
} catch (Exception e) {
// TODO Auto-generated catch block
throw new ServletException(e);
}
}
private void loadUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
String eid=request.getParameter("u_eid");
Employee themp=registerDbutil.getUser(eid);
//plaqce user in the request attribute
request.setAttribute("THE_USER", themp);
//send to jsp page:update -user-reg.jsp
RequestDispatcher dispatcher=
request.getRequestDispatcher("/user registartion.jsp");
dispatcher.forward(request,response);
}
RegisterDbUtil.java
public Employee getUser(String eid) throws Exception{
Employee theuser=null;
Connection myConn =null;
PreparedStatement myStmt=null;
ResultSet myRs=null;
try
{
//get connection to db
myConn=dataSource.getConnection();
//create sql to get selected user email
String sql="select email from employee where eid=? ";
//create prepared statements
myStmt=myConn.prepareStatement(sql);
myStmt.setString(1, eid);
//execute state
myRs=myStmt.executeQuery();
if(myRs.next())
{
String email=myRs.getString("email");
theuser=new Employee(email);
}
else
{
throw new Exception("Could not find employee id:" +eid);
}
return theuser;
}finally
{
close(myConn,myStmt,null);
}
}
Я ожидаю, что выходные данные предварительно заполнят html-форму сотрудника при вводе идентификатора сотрудника