javaEE框架获取和传参要使用的类和接口
1:spring
2:struts2获取前台数据(action中获取)
//4修改用户密码、
public String updateUserPassword() throws Exception{
Map session=ActionContext.getContext().getSession();
User user1=(User) session.get("user");
//user1.getPassword()获取的是数据库密码。||pwd1获取的是jsp输入密码
if (user1.getPassword().equals(getPwd1())) {
user1.setPassword(password);
userService.addOrUpdateUser(user1);
session.remove("user");//它的作用是移除jsp页面输入的数据
return SUCCESS;
}else{
Map request= (Map) ActionContext.getContext().get("request");
request.put("msg", "旧密码错误");
return ERROR;
}
}
2.2:在jsp值利用strut获取后台数据库数据
<s:form action="updateUserDetail.action" method="post"> <!--下面的"%"难 --> <s:textfield label="真实姓名" value="%{#session.user.userdetail.truename}" name="userdetail.truename"></s:textfield> <s:radio list="#{1:'男',0:'女' }" label="性别" value="%{#session.user.userdetail.xb}" name="userdetail.xb"></s:radio> <tr><td></td><td> <s:textfield label="出生日期" value="%{#session.user.userdetail.csrq}" name="userdetail.csrq"></s:textfield> </td> </tr> <s:textfield label="E-mail" name="userdetail.email" value="%{#session.user.userdetail.email}"></s:textfield> <s:textfield label="手机" name="userdetail.phone" value="%{#session.user.userdetail.phone}"></s:textfield> <s:textfield label="地址" name="userdetail.address" value="%{#session.user.userdetail.address}"></s:textfield> <s:submit value="确认"></s:submit> </s:form>
3:hibernate处理数据库数据
//org.hibernate.SessionFactory一般继承hibernate private SessionFactory sessionFactory; //它们在同一个类中,下面举例一个方法 public List getNewFlower() { Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); // 为什么这么写。因为select * 被hibernate添加写了 Query query = session.createQuery("from Flower order by flowerid desc"); query.setFirstResult(0); query.setMaxResults(4); List flowers = query.list(); tx.commit(); session.close(); return flowers; }