JSP操作技巧(摘自www.java-cn.com)
1 表单的另一种参数传递方法:
2 防止为登陆浏览:
if(session.getAttribute("UserName")==null||session.getAttribute("UserName")=="")
{
out.println("′javascript′>");
out.println("alert(′对不起!请你登陆后再订阅′)");
out.println("history.go(-1)");
out.println("");
}
else
{
%>
3验证 用户信息的合法性:
<%@ page language="java" import="java.sql.*" %>
<%! String bookid,bookNumS; int Id,bookNumI;
%>
<%
bookid=request.getParameter("bookid");//得到ID
bookNumS=request.getParameter("bookfield");//得到数量
if(bookNumS!=""&bookNumS!=null)
{
try
{
bookNumI=Integer.parseInt(bookNumS);//转换成int类型
Id=Integer.parseInt(bookid) ;
}
catch(NumberFormatException e)
{
out.println("′javascript′>");
out.println("alert(′对不起,您输入的数字格式不对!′)");
out.println("history.back(-1)");
out.println("");
}
boolean one=bookM.bookQuery(Id,bookNumI,""+session.getAttribute("loginTime"),""+session.getAttribute("UserName"));
if(one)
{
out.println("′javascript′>");
out.println("alert(′提交成功!′)");
out.println("history.back(-1)");
out.println("");
}
else
{
out.println("′javascript′>");
out.println("alert(′您已经订过此书!′)");
out.println("history.back(-1)");
out.println("");
}
}
bookM.bclose();
}
%>
4表单的检验
确定" οnclick=search_sub()>
/n"))));
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
3用javaBean 返回
public static void goback(JspWriter out)
{
try
{
out.print("/n");
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
4用bean 插入javascript
public static void goback(JspWriter out)
{
try
{
out.print("/n");
}
catch(Exception e)
{
System.out.println(e.toString());
}
}