我做的网站与Hibernate和Struts 2在Java中使用Ajax的。基本上,当我创建,修改任何本地内容(在的.java),如分配值 INT
,在下次检查其空
。这种情况发生的每一次。
I made website with Hibernate and Struts 2 with using of Ajax in Java. Basically, when I create, modify any local content (in .java), like assign value to int
, at next inspection its null
. This happens every time.
这是的struts.xml
我的大多数网页被召是这样的:
This is the struts.xml
most of my pages are bidden this way:
<action name="showclient" class="modelClass.LogInObject" method="show">
<result name="success" >/MyAccount.jsp</result>
</action>
客户端只是一个带有CRUD实施了滨类:
Client is just a bin class with CRUD implemented:
public class Client extends ActionSupport {
private static final long serialVersionUID = 1L;
private Long idClient;
private String login;
private String password;
private String nom;
private String prenom;
private String adresse;
private String ville;
private int cPostal;
private String email;
private Set<Commande> panier = new HashSet<Commande>(0);
// private static final Logger logger = Logger.getLogger(Client.class.getName());
public static Client logIn(String login, String password)
{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
String qstr = "SELECT * FROM client";
Query query = session.createSQLQuery(qstr).addEntity(Client.class);
List<Client> list = (List<Client>)query.list();
Iterator<Client> it = list.iterator();
while (it.hasNext())
{
Client client = it.next();
if (client.getLogin().compareTo(login) == 0 &&
client.getPassword().compareTo(password) == 0)
return client;
}
return null;
}
在 LogInObject
:
public class LogInObject extends ActionSupport {
private static final long serialVersionUID = 1L;
private Long loggedInId;
private String login;
private String password;
private String confirmPassword;
private String error;
public Client client;
public String login()
{
Client client = null;
if ((client = Client.read(Client.logIn(this.login, this.password).getIdClient())) != null)
{
this.client = client;
return SUCCESS;
}
this.login = "";
this.password = "";
this.error = "Bad login or password";
return ERROR;
}
public String show()
{
System.out.println(this.getClient().getIdClient());
return SUCCESS;
}
最后主类:
public class MainActionObject extends ActionSupport {
private static final long serialVersionUID = 1L;
private boolean logged;
private String search;
List<Produit> listProduit;
LogInObject loginObject;
public String login()
{
if (this.loginObject.login() == SUCCESS)
{
this.setLogged(true);
return SUCCESS;
}
return ERROR;
}
}
因此,显示()
在 loginobject
打印客户端的编号是从SQL基础阅读的时刻初始化我打印到的.jsp
页的所有信息 - [R那里,毕竟它已不再存在。即使我做的id以任何可能的方式进行备份。我知道CRUD的意思,所以不要告诉我正常的。
So the show()
in loginobject
prints id of client that was read from SQL base at the moment of initialization I print it to the .jsp
page all info r there and after all it no longer exist. even if I make a backup of id in any possible way. I know the meaning of CRUD, so don't tell me its normal.
推荐答案
好了,你的动作需要扩展了ActionSupport实现ServletRequestAware
当你的客户端登录成功
public String login()
{
...
getServletRequest().getSession().setAttribute("idClient", client.getIdClient());
public String show()
{
System.out.println(getServletRequest().getSession().getAttribute("idClient"));
相关推荐
最新文章