程序代码如下:
index.jsp
<%@ page contentType="text/html;charset=utf-8"%>
<jsp:useBean id="aaa" class="bean.Bean" scope="session"/>
<html>
<body>
<form action="/test04/action" method="post">
<input type=text name="abc">
<input type="submit" value="提交">
</form>
<!--<jsp:setProperty name="aaa" property="abc" param="abc"/>-->
</body></html>
b.jsp
<%@ page contentType="text/html;charset=utf-8" import="java.util.*"%>
<jsp:useBean id="aaa" class="bean.Bean" scope="session"/>
<html>
<body>
<jsp:getProperty name="aaa" property="abc"/>
</body>
</html>
Bean.java
package bean;
public class Bean {
public String abc;
public String getAbc() {
return abc;
}
public void setAbc(String abc){
this.abc=abc;
}
}
Serv.java
package servlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import bean.Bean;
public class Serv extends HttpServlet {
public void init(ServletConfig config) throws ServletException{
super.init();
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
Bean bean = new Bean();
bean.setAbc(request.getParameter("abc"));
RequestDispatcher dispatcher = request.getRequestDispatcher("b.jsp");
dispatcher.forward(request, response);
}
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
doPost(request, response);
}
}
推荐回答
还没有选出推荐答案,请稍候访问或查看其他回答!