如题,代码如下:
- HTML code
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%><%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 'example_0&1.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> <div align="center"> <p><strong>please choose</strong> <form name="form1" method="post"> <input type="checkbox" name="fruit" value="very bad!!!">very bad <input type="checkbox" name="fruit" value="general!!!">general <input type="checkbox" name="fruit" value="good!!!">good <input type="checkbox" name="fruit" value="very good!!!">very good</p> <p><strong>Gender:</strong> <input type="radio" name="sex" value="male">male <input type="radio" name="sex" value="female">female </p> <p><input type="submit" name="submit" value="submit"></p> </form> </div> </center> <% request.setCharacterEncoding("GBK"); String msg=""; String sex=request.getParameter("sex"); String fruit[]=request.getParameterValues("fruit"); int len=fruit.length; if(sex==null) {msg="please choose gender!!!<br>";} if(sex.equals("male")) {msg="Hello!Sir!<br>";} if(sex.equals("female")) {msg="Hello!Miss!<br>";} if(len==0) {msg=msg+"please choose fruit!!";} else { out.print("<h3>thanks!!!!!</h3><br>"); msg=msg+"you choosed:"; for(int i=0;i<len;i++) { msg=msg+fruit[i]+"/"; } } out.print(msg); %> </body></html>
------解决方案--------------------
编码 格式 改成 utf-8
------解决方案--------------------
要发布tomcat 服务器
------解决方案--------------------
列出错误信息。。。
------解决方案--------------------
你程序里面想要从request捕获的fruits信息没有从之前的页面传过来,而是你写在了同一个页面当中,我想这是问题的一个方面,这样处理request.getParameterValues("fruit")肯定就会有问题
------解决方案--------------------
有点乱,看不出来
------解决方案--------------------
- HTML code
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%><% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; request.setCharacterEncoding("GBK"); if(request.getParameter("isUsed") !=null) { String msg=""; String sex=request.getParameter("sex"); String fruit[]=request.getParameterValues("fruit"); int len=fruit.length; if(sex==null) {msg="please choose gender!!!<br>";} if(sex.equals("male")) {msg="Hello!Sir!<br>";} if(sex.equals("female")) {msg="Hello!Miss!<br>";} if(len==0) {msg=msg+"please choose fruit!!";} else { out.print("<h3>thanks!!!!!</h3><br>"); msg=msg+"you choosed:"; for(int i=0;i<len;i++) { msg=msg+fruit[i]+"/"; } } out.print(msg); } %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My 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> <div align="center"> <p><strong>please choose</strong> <form name="form1" method="post" action="problem.jsp"> <input type="hidden" name="isUsed" value="1" /> <input type="checkbox" name="fruit" value="very bad!!!">very bad <input type="checkbox" name="fruit" value="general!!!">general <input type="checkbox" name="fruit" value="good!!!">good <input type="checkbox" name="fruit" value="very good!!!">very good</p> <p><strong>Gender:</strong> <input type="radio" name="sex" value="male">male <input type="radio" name="sex" value="female">female </p> <p><input type="submit" name="submit" value="submit"></p> </form> </div> </body></html>