1.jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.cgm.test.Test"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'test.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
Test test=new Test();
String aa= test.prints(pageContext); //把jsp的out对象传到java里面。。。。。
%>
${jinlian}
</body>
</html>
2java类
package com.cgm.test;
import java.io.IOException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
public class Test {
public String prints(PageContext pageContext) throws IOException{
System.out.println("XXXXXXX被调用了。。。。");
//能得到out对象啊 被封装得
pageContext.getOut().print("KKKKKKKKKKKKKKKKKKKKKkk");
pageContext.getRequest().setAttribute("jinlian","你好金莲");
return "1234555555555555555";
}
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.cgm.test.Test"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'test.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
Test test=new Test();
String aa= test.prints(pageContext); //把jsp的out对象传到java里面。。。。。
%>
${jinlian}
</body>
</html>
2java类
package com.cgm.test;
import java.io.IOException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
public class Test {
public String prints(PageContext pageContext) throws IOException{
System.out.println("XXXXXXX被调用了。。。。");
//能得到out对象啊 被封装得
pageContext.getOut().print("KKKKKKKKKKKKKKKKKKKKKkk");
pageContext.getRequest().setAttribute("jinlian","你好金莲");
return "1234555555555555555";
}
}