modou

t1.htm

<html>
  
<head>
    
<title>test</title>

  
</head>
  
  
<body>
    
<form name="f1" id="f1" action="t1.jsp" method="post">
      
<table border="0">
        
<tr>
          
<td>内容:</td>
          
<td><input type="text" name="field1"></td>
        
</tr>
        
<tr>
          
<td colspan="2" align="center"><input type="submit" value="submit"></td>
        
</tr>
      
</table>
    
</form>
  
</body>
</html>

 

t1.jsp

<%@ page language="java" contentType="text/html; charset=GB2312" pageEncoding="GB2312"%>
<html>
    
<head>
        
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
        
<title>test</title>
    
</head>
    
<body>
        
<%=request.getParameter("field1")%>
    
</body>
</html>

 

提交表单使用 post 和 get 方式,或者通过网址传递的参数,都可以通过request.getParameter(name)来获取表单的数据。

 

 

 

要想在一个普通类中使用request,可以把PageContext以参数的形式引进去,代码如下:

public void MyFun(PageContext pageContext) throws Exception
{
        PrintWriter out 
= pageContext.getResponse().getWriter();
        ServletRequest request 
= pageContext.getRequest();
        out.print(request.getParameter(
"field1"));
}

 

在页面中这样使用:

<%
Class1 class1 
= new Class1();
class1.MyFun(pageContext);
%>

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-01-25
  • 2022-12-23
  • 2021-08-13
  • 2021-11-20
  • 2021-09-11
  • 2021-12-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-31
  • 2021-12-15
  • 2022-12-23
  • 2021-12-12
  • 2021-04-25
  • 2021-06-28
相关资源
相似解决方案