2017.5.9

  • main函数传递参数:
//控制台输出输入字符

import java.io.PrintStream;
public class MainTest {
    public static void toPrint(String string){
        System.out.print(string+" ");
    }
    public static void main(String[] args) {
        if(args.length==0) toPrint("No string inputed!");
        else
            for(String st:args) toPrint(st);
    }

}
  • JSP:
    session: 单个会话跟踪,如个人登录,在各个页面之间传递参数
    application: 共享的数据,如计数器:
//注意使用setAttribute时候的类型转换
//再次注意setAttribute的参数类型是String和obj, getAttribute的返回类型是obj

Integer number = (Integer)application.getAttribute("number");
if(number==null){
    number = new Integer(1);
    application.setAttribute("number", number);
}
else{
    number = new Integer(number.intValue()+1);
    application.setAttribute("number", number);
}
out.print("您是第位"+number+"登录的考生");

注意表格传递过来值的判断,如果不填写是""不是null??

String username = request.getParameter("username");
String password = request.getParameter("userpwd");

//out.print("Username:"+username+"Password"+password);
//**这里把null 换成了"", 是否为输入默认是空??

//判断+重新定向新页面,两种方式:直接跳转和等待刷新

if((username!="")&&(password!="")){
    session.setAttribute("user", username);
    response.sendRedirect("main.jsp");
}

你可能感兴趣的:(2017.5.9)