一、声明全局变量,局部变量
<%! int count=0;
%>
二、声明函数以及如何调用
<%! boolean isFac(int n){
boolean flag=true;
for(int i=2;i<=Math.sqrt(n);i++)
if(n%i==0) {flag=false;break;
}
return flag;
}
%>
三、声明类以及对象
<%!
public class Student{
String sno,sname,sclass;
public Student(String sno,String sname,String sclass){
this.sno=sno;this.sname=sname;this.sclass=sclass;
}
public String toString(){
return "sno="+sno+" sname="+sname+" sclass="+sclass;
}
}
%>
四、页面间如何传参数
1、HTMl 传给 jsp
<form method="get" action="Hello.jsp">
请输入半径:<input type="text" name="r"><br>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
http://localhost:8080/jsp/Hello.jsp?r=3.5 //get方式提交
http://localhost:8080/jsp/Hello.jsp?w=12&h=10
2、中文乱码问题解决
String name=request.getParameter("name");
String age=request.getParameter("age");
name=new String(name.getBytes("ISO-8859-1"));//重新编码
3、 jsp 传给 jsp
五、在jsp如何访问数据库
和java 编程完全相同
六、response 主要功能实现网站跳转
1、<a href="http://www.sina.com.cn">新浪</a>
2、response.sendRedirect("http://www.sina.com.cn");