Some important actions

原创 2004年08月25日 11:17:00

LoginAction.java

package vincent.actions;

import java.io.UnsupportedEncodingException;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


public class LoginAction extends Action{

 
public ActionForward perform(ActionMapping mapping,
  ActionForm form,
  HttpServletRequest request,
  HttpServletResponse response){
 //can logon?
 boolean isValidate = false;
 //get the LoginForm attribute
 String userName = ((LoginForm)form).getUsername();
 String passWord = ((LoginForm)form).getPassword();
 //validate
 if(userName.equals("Admin") && passWord.equals("Admin")){
  isValidate = true;
 }
 else if(userName.equals("Customer") && passWord.equals("Customer")){
  isValidate = true;
 }
 //add to ActionErrors
 if(isValidate == false){
  ActionErrors errors = new ActionErrors();
  errors.add(ActionErrors.GLOBAL_MESSAGE,new ActionError("error.login.failed"));
  this.saveErrors(request,errors);
  return mapping.findForward("Logon"); 
 } 
 //get the session
 HttpSession session = request.getSession();
 session.setAttribute("userName",userName);
 session.setAttribute("passWord",passWord);
 session.setAttribute("LoginForm",(LoginForm)form);//Put it in the session cause the jsp may use it
 return (mapping.findForward("View"));
  
  
}

}

LoginForm.java

package vincent.actions;


import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.ValidatorForm;


public class LoginForm extends ValidatorForm{
 //declare the fields of the form here
 private String username = null;
 private String password = null;

 
 public void setUsername(String username){
  this.username = username;
 }
 public void setPassword(String password){
  this.password = password;
 }
 public String getUsername(){
  return (this.username);
 }
 public String getPassword(){
  return (this.password);
 }
 /**
  * This is the validation
  * It must not be omitted.It MUST not be implemented cause the ValidationPlugin will do that.
  */
 public ActionErrors validate(ActionMapping mapping,HttpServletRequest request){
  return null;
 }
}

ViewAction.java

package vincent.actions;

import java.io.IOException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;

import javax.ejb.CreateException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import vincent.CMP.ProductLocal;
import vincent.SLSBean.*;
import vincent.util.PageControl;

public final class ViewAction extends Action{
 //cache the accessManagerHome here
 AccessManagerHome accessManagerHome = null;
 ArrayList productList = null;
 ArrayList array = new ArrayList();
 
 /**
  * Initializing the accessManagerHome
  *
  */
 public void initAccessManager(){
  System.out.println("Loading AccessManager in the servlet");
  try {
   accessManagerHome = getHome();
  } catch (NamingException e) {
   //Have to add something later
   e.printStackTrace();
  }
 }
 
 /**
  * Get the AccessManagerHome
  * @return
  * @throws NamingException
  */
 public AccessManagerHome getHome() throws NamingException {
  Object result = getContext().lookup(AccessManagerHome.JNDI_NAME);
  return (AccessManagerHome)PortableRemoteObject.narrow(result,AccessManagerHome.class);
 }
 
 /**
  * Get the Context for JNDI
  * @return
  * @throws NamingException
  */
 public InitialContext getContext() throws NamingException {
  Hashtable props = new Hashtable();

  props.put(
    InitialContext.INITIAL_CONTEXT_FACTORY,
  "org.jnp.interfaces.NamingContextFactory");
  props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");

  // This establishes the security for authorization/authentication
  // props.put(InitialContext.SECURITY_PRINCIPAL,"username");
  // props.put(InitialContext.SECURITY_CREDENTIALS,"password");

  InitialContext initialContext = new InitialContext(props);
  return initialContext;
 }
 
 public void setArrayList(ArrayList arrayList,PageControl pageControl){
  int startRow = pageControl.getPageStartRow();
  int endRow = pageControl.getPageEndRow();
  Iterator iterator = arrayList.iterator();
  for(int i=1;i<startRow;i++){
   iterator.next();
  }
  for(int i=startRow;i<=endRow;i++){
   ProductLocal element = (ProductLocal) iterator.next();
   ProductForm productform = new ProductForm();
   //add the info to productform
   productform.setId(element.getID().toString());
   //test whether it can add
   productform.setName(element.getName());
   productform.setRetailPrice(element.getRetailPrice().toString());
   productform.setWholeSalePrice(element.getWholeSalePrice().toString());
   productform.setQuantity(element.getQuantity().toString());
   productform.setDescription(element.getDescription());
   productform.setDiscountPrice(element.getDiscountPrice().toString());
   //add it to the list
   array.add(productform);
  }
 }
 /**
  * perform the main function here
  */
 public ActionForward perform(ActionMapping mapping,
   ActionForm form,
   HttpServletRequest request,
   HttpServletResponse response)
  throws IOException,ServletException{
  //At first I get the session
  HttpSession session = request.getSession();
  PageControl pageControl = (PageControl) session.getAttribute("pageControl");
  //get the username and password from the session.
     //if the IE has been restarted,return to the first index page
     String userName = (String) session.getAttribute("userName");
  String passWord = (String) session.getAttribute("passWord");
  //Validate here
  /*if(userName == null || passWord == null)
  {
   return (mapping.findForward("Logon"));
  }*/
  /*else if(!userName.equals("Admin") || !userName.equals("Customer"))
  {
   return (mapping.findForward("Logon"));
  }
  */
  
  //get the accessManagerHome initialized
  initAccessManager();
   //reset your array first
   array = new ArrayList();
   try {
    accessManagerHome.create().calculateDiscount((float)0.75);
   } catch (RemoteException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (CreateException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   try {
    productList = accessManagerHome.create().getAllRecords();
   } catch (RemoteException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
   } catch (CreateException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
   }
   //get the pages information from request
   String pageInfo = request.getParameter("pageInfo");
   //if null create the new PageControl
   if(pageInfo == null){
    pageControl = new PageControl(productList.size());
    session.setAttribute("pageControl",pageControl);
   }
   else if(pageInfo.equals("next")){
    pageControl.setCurrentPage(pageControl.getNextPage());
   }
   else if(pageInfo.equals("previous")){
    pageControl.setCurrentPage(pageControl.getPreviousPage());
   }
   //transfer the productlist to the array
   //in array the element in "ProductForm"
   setArrayList(productList,pageControl);
     //add the PageForm info
   PageForm pageForm = new PageForm();
   String hasNext = null;
   if(pageControl.hasNext){
    hasNext = "yes";
   }
   else{
    hasNext = "no";
   }
   String hasPrevious = null;
   if(pageControl.hasPrevious){
    hasPrevious = "yes";
   }
   else{
    hasPrevious = "no";
   }
  pageForm.setHasNext(hasNext);
  pageForm.setHasPrevious(hasPrevious);
     //add it to the session
  request.setAttribute("array",array);
  session.setAttribute("PageForm",pageForm);
  
  
  //redirect to ProductList.jsp with the same request(I will verify later)
  return mapping.findForward("ProductList");
  }
}

Android 秒级编译框架配置过程 --Freeline

Freeline是蚂蚁金服旗下一站式理财平台蚂蚁聚宝团队在Android平台上的量身定做的一个基于动态替换的编译方案,稳定性方面:完善的基线对齐,进程级别异常隔离机制。性能方面:内部采用了类似Face...
  • ocean20
  • ocean20
  • 2016年11月18日 13:23
  • 1454

css兼容教程(css中!important介绍)

css兼容教程   css兼容教程div+css使用!important标记区别Firefox和IE6 [使用!important标记可以区别Firefox和IE6] Firef...
  • DrifterJ
  • DrifterJ
  • 2013年01月29日 20:07
  • 5532

!important和js的优先级比较

一般情况下: [1位重要标志位] > [4位特殊性标志] > 声明先后顺序 !important > [ id > class > tag ]   使用!important可以改变优...
  • hsany330
  • hsany330
  • 2016年06月07日 11:37
  • 2379

【CSS】CSS选择器优先级及!important属性

CSS的选择器是有权重的,当不同选择器的样式设置有冲突时,会采用权重高的选择器设置样式。权重(即优先级)的规则如下,权重越高,优先级越高:   同一个元素可以使用多个规则来指定它的同一样式(比如...
  • Inite
  • Inite
  • 2016年10月08日 10:31
  • 557

ACTIONS S900 uboot阶段显示模块分析!

首先,显示子系统的相关代码在\u-boot\drivers\video\owl目录下,分析从owl_fb.c开始。 void *video_hw_init(void) { owl_pwm_init(...
  • goodtalent
  • goodtalent
  • 2017年02月24日 09:47
  • 362

IE各版本和FF对于\9,*,_,!important的支持

之前在网上看到一篇讲述CSS HACK的文章,主要用来区分的为\9,*,_,!important这四个。今天实验了一下,发现与文章中有一些出入,下面为IE各版本对于这几个的支持   ...
  • qingliuFu
  • qingliuFu
  • 2016年09月21日 11:02
  • 1231

css !important用法以及CSS样式使用优先级判断

之前一直看到很多css中都有!important这个样式,一直不知道有什么作用的,今天在网上详细了解了一下,看了别人的博客,顺便转载收藏一下 css !important用法CSS样...
  • zth1002
  • zth1002
  • 2015年06月11日 11:52
  • 1602

play framework框架进Debug,右键项目build path 空白(no actions available)等解决问题

play framework 框架是用scala语言写的,是编译后的文件直接在虚拟机上运行的,和java有点像,不管在什么平台都可以运行,所有项目启动的时候需要在命令行中启动和看打印信息,如果用习惯了...
  • u012757464
  • u012757464
  • 2015年08月13日 17:31
  • 3208

CSS---cursor鼠标属性

CSS改变鼠标指针形状的方法:在项目中会遇到需要点击的图片,字体,按钮等,就需要鼠标的指针形式变成小手型; 当文本款,文本域是禁止输入的时候,鼠标的指针变成红圈中间一道杠的形式;...
  • J_Y_X_8
  • J_Y_X_8
  • 2016年03月29日 20:42
  • 657

CSS 中 !important的用法总结

下面简要的给大家讲一下CSS 中一个比较重要的!important属性,从笔者的实践中总结了以下两点: 1、用于解决IE对某些CSS规范有偏差的情况.     比如在IE中的效果总是和其他的浏览器...
  • u013864585
  • u013864585
  • 2014年07月08日 14:11
  • 2871
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Some important actions
举报原因:
原因补充:

(最多只允许输入30个字)