接收数据的Servlet错误
The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.io.UnsupportedEncodingException: GB2321
sun.io.Converters.getConverterClass(Converters.java:218)
sun.io.Converters.newConverter(Converters.java:251)
sun.io.CharToByteConverter.getConverter(CharToByteConverter.java:68)
sun.nio.cs.StreamEncoder$ConverterSE.<init>(StreamEncoder.java:189)
sun.nio.cs.StreamEncoder$ConverterSE.<init>(StreamEncoder.java:172)
sun.nio.cs.StreamEncoder.forOutputStreamWriter(StreamEncoder.java:72)
java.io.OutputStreamWriter.<init>(OutputStreamWriter.java:82)
org.apache.tomcat.util.buf.WriteConvertor.<init>(C2BConverter.java:168)
org.apache.tomcat.util.buf.C2BConverter.<init>(C2BConverter.java:47)
org.apache.catalina.connector.OutputBuffer.setConverter(OutputBuffer.java:579)
org.apache.catalina.connector.OutputBuffer.checkConverter(OutputBuffer.java:545)
org.apache.catalina.connector.Response.getWriter(Response.java:619)
org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:196)
acceptUserRegist.doPost(acceptUserRegist.java:27)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.23 logs.
我的WEB.XML文件里已经有添加:
<servlet>
<servlet-name>acceptUserRegist</servlet-name>
<servlet-class>acceptUserRegist</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>acceptUserRegist</servlet-name>
<url-pattern>/servlet/acceptUserRegist</url-pattern>
</servlet-mapping>
我的提交数据的页面代码userRegister.jsp
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<script language="javascript">
function on_submit()
{//验证数据的合法性
if (form1.username.value == "")
{
alert("用户名不能为空,请输入用户名!");
form1.username.focus();
return false;
}
if (form1.userpassword.value == "")
{
alert("用户密码不能为空,请输入密码!");
form1.userpassword.focus();
return false;
}
if (form1.reuserpassword.value == "")
{
alert("用户确认密码不能为空,请输入密码!");
form1.reuserpassword.focus();
return false;
}
if (form1.userpassword.value != form1.reuserpassword.value)
{
alert("密码与确认密码不同");
form1.userpassword.focus();
return false;
}
if (form1.email.value.length!= 0)
{
for (i=0; i<form1.email.value.length; i++)
if(form1.email.value.charat(i)=="@")
break;
if (i==form1.email.value.length)
{
alert("非法E-mail地址!");
form1.email.focus();
return false;
}
}
else
{
alert("请输入E-mail!");
form1.e-mail.focus();
return false;
}
}
</script>
<html>
<head>
<title>新用户注册</title>
</head>
<body>
<form method="POST" action="servlet/acceptUserRegist" name="form1" onsubmit="return on_submit()">
新用户注册<br>
用户名(*):<input type="text" name="username" size="20"><br>
密码(*):<input type="password" name="userpassword" size="20"><br>
再输入一次密码(*):<input type="password" name="reuserpassword" size="20"><br>
性别:<input type="radio" value="男" checked name="sex">男<input type="radio" name="sex" value="女">女<br>
出生年月:<input name="year" size="4" maxlength=4>年
<select name="month">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>月
<input name="day" size="3" maxlength=4>日<br>
电子邮箱(*):<input name="e-mail" maxlength=28><br>
家庭住址:<input type="text" name="address" size="20"><br>
<input type="submit" value="提交" name="B1">
<input type="reset" value="全部重写" name="B2"><br>
</form>
</body>
</html>
接收数据的Servlet代码:acceptUserRegist.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class acceptUserRegist extends HttpServlet
{
public String codeToString(String str){
String s=str;
try
{
byte tempB[]=s.getBytes("ISO-8859-1");
s=new String(tempB);
return s;
}
catch(Exception e)
{
return s;
}
}
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
response.setContentType("text/html;charset=GB2321");
PrintWriter out=response.getWriter();
out.println("这是新用户注册所提交的数据:<br>");
out.println("用户名是:"+codeToString(request.getParameter("username"))+"<br>");
out.println("密码是:"+codeToString(request.getParameter("userpassword"))+"<br>");
out.println("性别是:"+codeToString(request.getParameter("sex"))+"<br>");
out.println("出生年月是:"+request.getParameter("year")+ request.getParameter("month")+ request.getParameter("day")+"<br>");
out.println("电子邮箱是:"+request.getParameter("e-mail")+"<br>");
out.println("家庭住址是:"+codeToString(request.getParameter("address"))+"<br>");
out.println("</body></html>");
}
}
请问谁能帮忙试运行下?
[解决办法]
我也纳闷呢
[解决办法]
路过,不能白来,接分。
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html