index.jsp如下:
<html>
<head>
<title>JSP中使用 Java Bean的测试</title>
</head>
<body> 
<jsp:useBean id="go" class="test.SimpleBean" /> <p>消息:
<% go.p();%>
</body>
</html>
test.SimpleBean如下:
package test;
public class SimpleBean
{
    private String message;
   
    public void p(){
      System.out.println("hi");
    }
   
}
为什么打印输出是什么都没有?
能不能不用那种setproperty getproperty地方法用java类在jsp页面打印输出一下呢?大哥们给个例子谢谢

解决方案 »

  1.   

    两个地方修改一下。
    <%=go.p();%> 
    public String p(){
        return "hi";
      

  2.   

    在后台做好相关的操作后,把它们request.setAttribute()里,然后在页面request.getAttribute();然后就想怎么用就怎么取了啊
      

  3.   

    晕了,刚才tomcat重启中,等会啊
      

  4.   

    楼上正解
     System.out.println("hi"); 是把“hi”打印到控制台了
     out 用来传送回应的输出 
     jsp中显示要用out.println("");或<%=%>
      

  5.   

    这回真晕了
    index.jsp:
    <html>
    <head>
    <title>JSP中使用 Java Bean的测试</title>
    </head>
    <body> 
    <jsp:useBean id="tes" class="test.SimpleBean" />
    <jsp:setProperty name="tes" property="message" value="Hello JSP"/>
    <p>消息:
    <jsp:getProperty name="tes" property="message" />
    </body>
    </html>
    SimpleBean.jsp:
    package test; 
     public class SimpleBean
    {
        private String message;    public String getMessage()
        {
          return message;
        }
        public void setMessage(String message)
        {
          this.message = message;
        }
    }
    运行了屏幕页面一片空白
      

  6.   

    晕死 没加
    <%@ page language="java" import="java.util.*" contentType="text/html" pageEncoding="GB2312"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>