网页不能访问,提示500文件不能找到

powerApower 2016-10-08 02:30:08
package web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloServlet extends HttpServlet {
public void service(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,IOException{
//设置服务器返回的数据类型

//读取请求参数值
String qty=request.getParameter("qty");

String uname=request.getParameter("uname");
String greeting="";
/*
* 通常在对请求参数做一些检查
*/
for(int i=0;i<Integer.parseInt(qty);i++){
greeting +="<h1>你好:"+uname+"</h1>";

}
response.setContentType("text/html;charset='utf-8'");
PrintWriter out=response.getWriter();
out.println(greeting);
out.close();
}

}









hello。html中文件
<html>
<head>
<!-- 模拟content-type消息头 -->
<meta http-equiv="content-type"
content="text/html;charset=utf-8">
</head>
<body style="font-size:30px;">
<form action="hello" method="post">
<fieldset>
<legend>欢迎</legend>
次数:<input name="qty"/><br/>
姓名:<input name="uname"/><br/>
<input type="submit" value="确定"/>


</fieldset>

</form>

</body>


</html>






web.xml中文件


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>helloServlet</servlet-name>
<!-- 完整的类名 -->
<servlet-class>web.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>


</web-app>






控制板中提示

2016-10-8 14:23:15 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [helloServlet] in context with path [/web01] threw exception
java.io.UnsupportedEncodingException: The character encoding ['utf-8'] is not supported
at org.apache.tomcat.util.buf.B2CConverter.getCharsetLower(B2CConverter.java:91)
at org.apache.tomcat.util.buf.B2CConverter.getCharset(B2CConverter.java:78)
at org.apache.tomcat.util.buf.C2BConverter.<init>(C2BConverter.java:41)
at org.apache.catalina.connector.OutputBuffer.setConverter(OutputBuffer.java:619)
at org.apache.catalina.connector.OutputBuffer.checkConverter(OutputBuffer.java:581)
at org.apache.catalina.connector.Response.getWriter(Response.java:683)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:213)
at web.HelloServlet.service(HelloServlet.java:30)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1083)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:640)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:619)
2016-10-8 14:23:15 org.apache.coyote.http11.AbstractHttp11Processor process
严重: Error processing request
java.lang.NullPointerException
at org.apache.catalina.connector.OutputBuffer.realWriteChars(OutputBuffer.java:478)
at org.apache.tomcat.util.buf.CharChunk.flushBuffer(CharChunk.java:464)
at org.apache.catalina.connector.OutputBuffer.close(OutputBuffer.java:292)
at org.apache.catalina.connector.Response.finishResponse(Response.java:537)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:480)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1083)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:640)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:619)
...全文
403 点赞 收藏 1
写回复
1 条回复
逝_去_的_光_阴 2016年10月08日
response.setContentType("text/html;charset='utf-8'");的'utf-8'单引号去掉试试?
回复 点赞
发动态
发帖子
Apache
创建于2007-09-28

1.1w+

社区成员

1.6w+

社区内容

Web 开发 Apache
社区公告
暂无公告