随笔 - 15, 文章 - 0, 评论 - 5, 引用 - 0
数据加载中……

处理隐藏表单的方法

实例名称:  满意度调查表


HTML页面代码

<html>
<head>
<title> 网站使用满意度调查 </title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>

<form method="post" action="/webproject1/servlet/loginlorm1">
<input type="hidden" name="survey_type" value="满意度调查">
<table border="0">
 <tr>
  <td align="right">您对本网站提供的所有服务满意吗?</td> 
 </tr>
  <tr>
   <td>
   <input type="submit" name="attitude" value="满意">
   <input type="submit" name="attitude" value="不满意">
    </td>
  </tr>
</table>
</form>
</body>
</html>


servlet中的代码

package com.v503.zhouzhou;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class LoginForm1 extends HttpServlet {

 public void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {

                  doPost(request,response);
 }


 @SuppressWarnings("unchecked")
 public void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  response.setContentType("text/html;charset=utf-8");
  PrintWriter out = response.getWriter();
  out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
  request.setCharacterEncoding("utf-8");
  out.println("<HTML>");
  out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
  out.println("  <BODY>");
 // 处理方法
  @SuppressWarnings("unused")
  Enumeration  e=request.getParameterNames();
  @SuppressWarnings("unused")
  String parameter=null;
  while(e.hasMoreElements()){
   parameter=(String)e.nextElement();
   @SuppressWarnings("unused")
   String value[]=request.getParameterValues(parameter);
   out.println(parameter+"<br>");
   out.println("<ul>");
  for(int i=0;i<value.length;i++)
  out.println("<li>"+value[i]+"</li>"); 
  out.println("</ul>"); 
  }

  out.println("  </BODY>");
  out.println("</HTML>");
  out.flush();
  out.close();
 }
 public String filterHtml(String value){
  value=value.replaceAll("&","&amp");
  value=value.replaceAll("<", "&lt;");
  value=value.replaceAll(">", "&gt;");
  value=value.replaceAll(" ","&nbsp;");
  value=value.replaceAll("'","value39;");
  value=value.replaceAll("\"","value;");
  value=value.replaceAll("\n", "value");
  return value;
 }

}





posted on 2008-07-29 21:22 zhouzhou@ 阅读(545) 评论(0)  编辑  收藏


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


网站导航: