java - 如何从运行在 Apache Tomcat 服务器上的 Java servlet 重定向到本地 HTML 文件?
问题描述
我创建了一个简单的 Java servlet,它从 HTML 表单中获取登录凭据。我检查用户名和密码,然后相应地重定向到本地 HTML 页面。使用命令 response.sendRedirect 时出现“404:找不到资源”错误。我知道错误在哪里。我不确定相对 URL 是怎样的。我已将这两个 HTML 文件放在 sendRedirect 参数中提供的路径中。
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
String username = request.getParameter("username");
String password = request.getParameter("password");
System.out.println(username);
System.out.println(password);
if((username.equals("xxx"))&&(password.equals("yyy")))
{
response.sendRedirect("http://localhost:8080/MyServer/WebContent/correct.html");
}
else
{
response.sendRedirect("http://localhost:8080/MyServer/MyServer/WebContent/wrong.html"); }
}
解决方案
推荐阅读
- php - 过滤表文本框不起作用?
- javascript - 如何存根 new Worker()
- python - 带注释字段的过滤器集查找
- python - 在函数内停止程序(python)
- ruby-on-rails - ruby on rails 心理测量应用程序
- c# - Rabbitmq RPC - amq.gen 太多
- git - 是否可以将多个本地文件夹连接到 Github 中的一个存储库?
- json - Angular6 Div 围绕来自同一用户的数组
- javascript - 单击其中的下拉菜单消失
- consul - spring cloud consul config app使用哪些端口与consul通信?