在项目中实现不了,写了个测试页面,显示结果是乱码,大家看看什么问题:代码:
<%@ 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>
<%@ 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>
解决方案 »
- HTTP method POST is not supported by this URL ??
- SQL Server 2005的数据库端口问题
- JSP很基础的问题
- jsp 无法显示目录下的文件名
- 下拉菜单中值是否可以自动捕获?
- jsp仿动网论坛!安装---调试---失败---郁闷!!!!!!!!!!
- 求教,怎么在Servlet中定义一个作用域为Application,类型为type的变量。
- 字符转换错误
- 输入一个汉字,即知它的拼音字头,源程序,二月十五号发放!希望对你有用。
- 关于SpringMVC事务(SpringMVC+JDBCtemplate)
- jsp页面提交form但不刷新怎么解决有没有完整的例子
- swfupload关于上传队列图片的上传顺序问题?
var a = document.getElementByName();
加一句:request.setCharacterEncoding("GB18030");由于servlet默认的编码方式是ISO-8859-1,不支持中文,会导致中文乱码。所以当有中文参数提交给Servlet或由Servlet输出中文到页面时,需要在处理前将其编码方式设置为兼容中文方式,即方法request.setCharacterEncoding("gbk")或response.setCharacterEncoding("gb2312")。呃,jsp页面page指令的pageEncoding属性的设置无法影响处理它的Servlet的编码。