import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ForwardServlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
res.setContentType( "text/html;charset=gb2312 ");
RequestDispatcher rd=getServletContext().getRequestDispatcher();
rd.forward( "/index.html ");
}
}
以下是我的xml 配置文件!
<servlet>
<servlet-name> AnyName </servlet-name>
<servlet-class> ForwardServlet </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> AnyName </servlet-name>
<url-pattern> /servlet/ForwardServlet </url-pattern>
</servlet-mapping>
访问时出现500错误!
这是怎么回事儿啊。请教达人!
------解决方案--------------------
<servlet-class> ForwardServlet </servlet-class>
例如 <servlet-class> com.test.ForwardServlet </servlet-class>
放到一个指定的package下面看看
好象放在默认的包下面有问题,我以前也遇到过这样的问题
------解决方案--------------------
try {
RequestDispatcher requestDispather=request.getRequestDispatcher( "/index.html ");
requestDispather.forward(request,response); } catch (Exception e) {
e.printStackTrace();
}
建议加上异常捕捉 因为那两句可能会抛出异常 而且楼主你再查看一下你要跳转的页面的路径是否正确