java技术博客

jsp博客
数据加载中……
jsp中使用类



package mypack;
class Student 
{
    
private int age;
    
private String xm;
    
private float mark;
    
public void setAge(int age){
        
this.age=age;
        }

        
public int getAge(){
        
return age;
        }

        
public void setXm(String xm)
    
{
        
this.xm=xm;
        }

        
public String getXm()
    
{
        
return xm;
        }

        
public void setMark(float mark)
    
{
        
this.mark=mark;
        }

        
public float getMark(){
        
return mark;
        }

        

}



package mypack;
class Say 
{
    
public String hello(String xm) 
    
{return "Hello World "+xm;
    }

}






<%@page language="java" import ="java.util.*,mypack.*" pageEncoding="GBK"%>
   <%@import="....."%>//用于多个包的导入
<%!
public int add(int x,int y)
{
return x+y;
}

int a=10;

%>


<%
Student stu
=new Student();
stu.setAge(
29);
stu.setXm(
"guoxinghua");
stu.setMark(
200.0F);
int a=100;
%>
<%Say s=new Say()%>
<%=s.hello(stu.getXm())%>
<%=s.add(10,20)%><%=stu.getAge()%>
<%=stu.getXm()%>
<%=stu.getMark()%>
<%=this.a%>
<%=a%>

<%%>这种是代码段,在这里声明的方法和变量是在局部的
<%!%>这种是声明语句,在这里声明的变量和方法是全局的
 <%=%>这种是表达式

posted on 2008-10-25 11:55 郭兴华 阅读(226) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: