struts学习笔记——参数接收

来源:互联网 发布:形容梦醒怅然若失知乎 编辑:程序博客网 时间:2024/05/17 23:59

hibernate项目如果更改src的目录,需要更改的地方:
首先,hibernate.cfg.xml中<mapping resource="Xxx/Xxx/Xxxx.hbm.xml"/>
其次:Xxxx.hbm.xml中<class name="Xxx.Xxx.Student"> 

 

用Action怎么接收参数:
三种方式:
1,在action中定义jsp中相对应的属性,name,age等,定义getter和setter方法。

2,在action中引入mode包(预模型),这种方法就只能在所有的属性都一样多的时候使用。
private User user;
public String add(){
 System.out.println("name="+user.getName());
 System.out.println("age="+user.getAge());
}
public User getUser(){
 return user;
}
public void setUser(User user){
 this.user = user;
}
但是这么做,在JSP页面的接收参数的属性名称就得命名为:user.id,user.name等等。


在参数不一致的时候:vo & dto & do
新建一个UserDTO类:(比demo中的属性更多,接收表单传递的超过bean的属性范围的属性)
public class UserDTO{
 private String name;
 private String password;
 private Stirng configPassword;
}
在action中将public User user;换为public UserDTO userDTO;
当然,相对应的getter和setter方法要改为userDTO的。


3:模型驱动,用的少

 

 

注意:——大小写
String 里面有5个static 常量分别是:
ERROR  INPUT LOGIN NONE SUCCESS
例如 如果在excute 中返回的是 ruturn SUCCESS;
也就相当于返回的是return "success"字符串
就必须在struts.xml中写上对应的"success"
<result name="success">/x.jsp</result>

当然EORROR 对应的就是"error";字符串
当然INPUT 对应的就是"input";字符串
当然LOGIN 对应的就是"login";字符串
当然NONE 对应的就是"none";字符串

 

 


问题:
用Action接收参数和用servelet接收参数的区别?

 

struts.xml的包含:
可以<include file = “login.xml”>使用这种方式。这样可以将别的配置直接拿来进行使用。分块开发就是这么来的。

 

默认action:
<default-action-ref name = "index"></default-action-ref>
可是调试么有通过,这是为什么?

 

全局结果集:所有的action只要返回mainpage就可以直接调转到main.jsp。但是放在程序出会报错。。。。。
  <globle-result>
   <result name = "mainpage">/main.jsp</result>
  </globle-result>

 

 

 

 

 

********************************************************************************
Hibernate:

annotation:
当在实体类中加入annotation(@Entity,@Id)的事时候就可以省略Xxxx.hbm.xml这个文件了,而只需要在hibernate.cfg.xml中加入:<mapping class = "xxx.xxx.xxx.Teacher">


但是Configuration cfg = new Configuration();要改为Configuration cfg = new AnnotationConfiguration();


如果是hibernate工厂呢?则么改?
 

原创粉丝点击