السلام عليكم و رحمة الله و بركاته
لاول مرة اتعامل مع j2ee ... لدي مشكلة في الواجهة الاولى و هي login in and login out
استخدمت struts2
لا ادري كيف انقل نتيجة resultset اسم الشخص من action class الى succesful.jsp ????
package com.myapp.struts;
import Utilitaire.MaConn;
import java.sql.ResultSet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;
public class loginAction extends org.apache.struts.action.Action {
/*
* forward name="success" path=""
*/
private static final String SUCCESS = "success";
private String na;
/**
* This is the action called from the Struts framework.
*
* @param mapping The ActionMapping used to select this instance.
* @param form The optional ActionForm bean for this request.
* @param request The HTTP Request we are processing.
* @param response The HTTP Response we are processing.
* @throws java.lang.Exception
* @return
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
loginForm lf = (loginForm)form;
String name =lf.getLog();
String password = lf.getPassword();
String sql ="select * from users where login='"+name+"' and password ='"+password+"'";
MaConn m= new MaConn();
m.connecter("jdbc:mysql://localhost:3306/struts", "root", "admin");
ResultSet rs=m.selection(sql);
String forward;
if(rs.next())
{
forward = "success";
na =rs.getString("nom");
}
else
{
ActionMessages errors = new ActionMessages();
ActionMessage error = new ActionMessage(
"errors.login.password.invalid");
errors.add("errors.invalid", error);
saveErrors(request.getSession(), errors);
loginForm lq = (loginForm)form;
lq.setLog("");
lq.setPassword("");
return mapping.getInputForward();
}
return mapping.findForward(forward);
}
}<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="./CSS/Styles.css" rel="stylesheet" type="text/css" media="screen">
<title>JSP Page</title>
</head>
<body>
<div id="bandeau">
<img src="images/logo.jpg" />
</div>
<div id="contenu">
Hello ,
</div>
</body>
</html>