在项目中实现不了,写了个测试页面,显示结果是乱码,大家看看什么问题:代码:
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
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 'testselect.jsp' starting page</title>
</head>
<%
ArrayList nu = new ArrayList();
nu.add("一");
nu.add("二");
nu.add("三");
%>
<body>
This is my JSP page.
<br> <form method=post action="testselect.jsp">
<select name=number>
<%
for (int i = 0; i < nu.size(); i++) {
out.print("<option>" + nu.get(i) + "</option>");
}
%>
</select>
<input type="submit" value="提交" name="submit">
</form>
</body>
<%//取得提交的数字,并显示
String n = (String) request.getParameter("number");
out.print(n);
%>
</html>

解决方案 »

  1.   

    本页面的request里面肯定没有啊,你得提交form后的request中才会有,如果你想在本页面获得就用js获得啊
    var a = document.getElementByName();
      

  2.   

    用js取得选择内容后,怎么传给本页的java的变量???
      

  3.   

    终于找到问题了:是编码问题。
    加一句:request.setCharacterEncoding("GB18030");由于servlet默认的编码方式是ISO-8859-1,不支持中文,会导致中文乱码。所以当有中文参数提交给Servlet或由Servlet输出中文到页面时,需要在处理前将其编码方式设置为兼容中文方式,即方法request.setCharacterEncoding("gbk")或response.setCharacterEncoding("gb2312")。呃,jsp页面page指令的pageEncoding属性的设置无法影响处理它的Servlet的编码。