在Struts1.1-1.2中如果不想没有登录的用户访问一些action,可以扩展RequestProcessor,并重载processProprocess方法,在其中进行验证
public class CustomRequestProcessor
extends RequestProcessor {
protected boolean processPreprocess (
HttpServletRequest request,
HttpServletResponse response) {
HttpSession session = request.getSession(false);
//If user is trying to access login page
// then don't check
if( request.getServletPath().equals("/loginInput.do")
|| request.getServletPath().equals("/login.do") )
return true;
//Check if userName attribute is there is session.
//If so, it means user has allready logged in
if( session != null &&
session.getAttribute("userName") != null)
return true;
else{
try{
//If no redirect user to login Page
request.getRequestDispatcher
("/Login.jsp").forward(request,response);
}catch(Exception ex){
}
}
return false;
}
}
相应的,在struts-config.xml中加入controller元素
<controller>
<set-property property="processorClass"
value="com.sample.util.CustomRequestProcessor"/>
</controller>
但刚才看到在Struts1.3中,已经不再使用RequestProcessor,而是用ComposableRequestProcessor 来实现自定义的request响应。
posted @
2007-04-09 18:52 hijeff 阅读(436) |
评论 (0) |
编辑 收藏
三个@Entity类Tc, Tracer, Track是三向关联的的表, @Embeddable类TcTracer则存储着三个表的ForeignKey
@Entity
@Table(name= "tc", catalog="first_hiber")
public class Tc {
@org.hibernate.annotations.CollectionOfElements
@JoinTable(name="tc_tracer", joinColumns=@JoinColumn(name="tc_id"))
private Set<TcTracer> tcTracers = new HashSet<TcTracer>();
@Id @GeneratedValue
@Column(name="tc_id", nullable= false)
private Long id;
}
@Embeddable
@Table(name="tc_tracer")
public class TcTracer {
@org.hibernate.annotations.Parent
private Tc tc;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="tracer_id", nullable=false, updatable=false)
private Tracer tracer;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="track_id", nullable=false, updatable=false)
private Track track;
}
如上,将TcTracer作为Tc的子元素,从而实现Tc的三相关联。
用HQL可以通过特定的Tc,Tracer得到对应的所有Track:
select tctracers.track
from Tc tc
join tc.tcTracers tctracers
where tc.name="tc name"
and tctracers.tracer.name="tracer name"
List<Track> tracks = session.createQuery(HQL).list();
posted @
2007-04-02 17:45 hijeff 阅读(373) |
评论 (0) |
编辑 收藏