[JSP代码运行错误的问题及解决方法] 运行时出错 错误代码1

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
解决方案:META-INF 下context.xml文件的配置出错或名字引用不到.名字如标签,只能是context.

ng.IllegalStateException/Attempt to clear a buffer that’s already been flushed
严重: Servlet.service() for servlet jsp threw exception
ng.IllegalStateException
解决方案:可以在response.sendRedirec(a.jsp)之后加return或者把路径变为./a.jsp。不过,都不管用。解决方法是设置buffer的大小:<%@ page buffer="10kb"%> 默认是8kb,自己手动改为10kb之后,没有错误了。
? The type Date is ambiguous
原因:
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*"%>
这两个类中都有Date,系统不知道选哪个了

解决方案: 可以用java.util.Date today=new Date();来区分
? (1)MySQL插入时的乱码:自己的MySQL安装时默认是用UTF-8的,在JSP中传入需要插入的数据时,可以用new String(request.getParameter(string).getBytes("ISO8859-1"), "UTF-8");插入后没有乱码……连接时用:String url = "jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf-8";

(2)页面的乱码:用非英语语言时,容易出现乱码,特别是在进行form提交表单检测时,如:“保存”.equals(str)时,有可能不识别,最好的是用隐藏表单提交,value值设为数字即可。如果有多个表单提交,可以用JavaScript检测设置隐藏表单的值:
<script type="text/javascript">
function getAction(num){
document.getElementById("hide").value=num;
}
</script>
<form>
<input name="action" type="hidden" value="" id="hide">
<input type="submit" onClick="getAction(1)" name="" value="保存" style="width: 70px" />
<input type="submit" onClick="getAction(2)" name="" value="リセット" style="width: 70px" />
<input type="submit" onClick="getAction(3)" name="" value="戻る" style="width: 70px" />
</form>

还有就是添加
<%@ page lpageEncoding="utf-8" %><!-- shift_jis -->

<%@page contentType="text/html;charset=utf-8"%>
<%
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
%>也可一定程度防止乱码。

<input type="text" name="name" id="name" value=<%=bean.getName() %> size="12" maxlength="12" />
如上所示,input通过value属性来获得数据库bean的数据。
? 而换成textarea时,这样做却不成。(当然数据库中有这项数据,你可以用out方法打印出来)

问题解决:
? 想到几个月前,做过一个新闻相关的网站。当时也用到textarea标签。
对照代码一看才明白过来,示例如下:
<textarea type="text" name="contents" > <%=bean.getContents() %> </textarea>
即将所需数据放在标签的中间就可以了!