自己为了测试servlet,用MyEclipse2015写了一个简单的登录程序。

1.登录页面index.jsp.

 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String lUserName = (String)session.getAttribute("iUserName");
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta charset="utf-8">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head> <body>
<%
if (lUserName != ""&&lUserName!=null) {
%>
欢迎光临,<%=lUserName%>
<%
} else {
%>
<form name="loginfrm" action="loginserv" method="post">
用户名:<input type="text" name="username" value="zhangsan"><br>
密码:<input type="text" name="password" value="mm123456"><br>
<input type="submit" value="登录">
</form>
<%
}
%>
</body>
</html>

2.用模版写了一个servlet程序loginserv.java.

 package com.kaly.servlet;

 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 loginserv extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html);charset=utf-8");
String getUser=request.getParameter("username");
String getpassword=request.getParameter("password");
PrintWriter pw=response.getWriter();
pw.print(getUser);
} }

这是一个很简单的程序,在收到请求后,把用户名打印出来。
3.运行出现问题:The requested resource is not available.

4.查找咨询,没有解决。后来查看web.xml。

 <?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
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_3_0.xsd">
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>loginserv</servlet-name>
<servlet-class>com.kaly.servlet.loginserv</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>loginserv</servlet-name>
<url-pattern>/servlet/loginserv</url-pattern>
</servlet-mapping> </web-app>

因为这些都是自动生成,没有想到过会出现问题。不过记起以前写这个程序时<url-pattern>节点只是在<servlet-name>节点内容前多一个"/",尝试将其改为/loginserv,重启服务运行页面。一些正常。

总结:这应该是这种问题出现的其中一种解决途径。

Servlet中The requested resource is not available错误的更多相关文章

  1. 调用servlet报The requested resource is not available.

    调用servlet的时候经常有这种报错,一般来说我直到现在遇到的情况大致有以下几类: 1.参数写错了 在新创建的servlet文件中有这么一行代码,“/LoginCheck”这个一定要和form表单中 ...

  2. 在IE浏览器输入测试servlet程序报:HTTP Status 404(The requested resource is not available)错

    一.HTTP Status 404(The requested resource is not available)异常主要是路径错误或拼写错误造成的,请按以下步骤逐一排查: 1.未部署Web应用 2 ...

  3. 在k8s中安装flannel的故障解决: Failed to create SubnetManager: error retrieving pod spec for : the server does not allow access to the requested resource

    花了一个上午来追踪问题,k8s都反复新建了十多次,docker都重启了几次.(一次显示不有获取磁盘空间,重启docker,清空存储解决) 在用kubeadm安装容器化的几个组件时,flannel组件死 ...

  4. (转)AJax跨域:No 'Access-Control-Allow-Origin' header is present on the requested resource

    在本地用ajax跨域访问请求时报错: No 'Access-Control-Allow-Origin' header is present on the requested resource. Ori ...

  5. HTTP Status 404(The requested resource is not available)的几种解决方案

    1. 未部署Web应用 2.URL输入错误       排错方法:首先,查看URL的IP地址和端口号是否书写正确.其次,查看上下文路径是否正确 Project--------Properties--- ...

  6. The requested resource (/) is not available解决办法

    The requested resource (/) is not available HTTP Status 404(The requested resource is not available) ...

  7. 转:HTTP Status 404(The requested resource is not available)的几种解决方法

    原文地址 原因:servlet没有配置正确 ,查看web.xml确认正确,以及自己的请求路径正确 在IE中提示“404”错误有以下三种情况 1.未部署Web应用 2.URL输入错误 排错方法: 首先, ...

  8. 分享HTTP Status 404(The requested resource is not available)的几种解决方案解决方法

    下面是直接copy的,如果有什么疑问or补充,请不吝指教! 原文地址:http://www.myexception.cn/java-web/1480013.html 这个问题搞了我两天的时间,找了各种 ...

  9. 错误:“The requested resource () is not available.”的处置

    做网页过程中,某页需要以新窗方式打开另一个网页,于是url是这样写: pages/test/transw/claimer.html 但是,点链接后网页提示 The requested resource ...

随机推荐

  1. 有关C# struct的一个误区

    参考:http://blog.csdn.net/onlyou930/article/details/5568319 下面写一个新的例子: using System; using System.Coll ...

  2. iOS 指定圆角个数

    需要实现的效果很明确,只要左上和右上两个地方圆角,以前都是通过layer 直接设置四个角都变成圆角,然后我就开始了强大的搜索功能 然后我就获得了我想要的东西 技术链接:http://www.xuebu ...

  3. mysql 操作杂记

    SHOW VARIABLES LIKE 'character%'; SET character_set_client = utf8; SET character_set_connection = ut ...

  4. aspx在页面跳转(Response.Redirect)时丢失session问题及解决办法

    [问题描述] 假设a.aspx.cs页面保存有Session["empid"]="3",当a.aspx.cs通过Response.Redirect(" ...

  5. 《1---关于解决MySQL在控制台插入中文乱码问题》

    说明:以下所有操作都是基于我个人的电脑及示例,读者可以参考我这个解决过程,去解决自己的问题,如有其它疑问,欢迎留言交流. 首先来看看我遇到的问题: [1]查看数据库: [2]使用test数据库: [3 ...

  6. MyBatis中出现Mapped Statements collection does not contain value

    引用csdn上一大神的解决方法: 经过排查,解决上述异常的过程如下: 1.确定xml文件中<mapper namespace=""/>中的namespace是否路径正确 ...

  7. TOMCAT运行一段时间后网页无响应或连不上,TOMCAT无错误日志

    解决方法:修改 tomcat 的 java options 参数1)增加java options参数-Xmn384m-XX:MaxPermSize=128m-XX:+UseConcMarkSweepG ...

  8. 64位系统下找不到office 32位组件

    如果系统式64位的,而装的是32位的office软件,在运行栏中输入命令:dcomcnfg,打开组件服务管理窗口,但是却发现找不到Microsoft Excel程序, 这主要是64位系统的问题,exc ...

  9. VS2010编译Boost 1.57 静态链接库

    http://www.cnblogs.com/cuish/p/4175491.html 0.前提 Boost库版本 1.57.0 下载地址 http://www.boost.org/users/his ...

  10. 阿里云弹性Web托管的URL重写问题

    今天将ThinkPHP写的网站搭到阿里云的弹性Web托管服务器上,出现路由问题 诸如访问 www.xxx.com/home/index.html会发生错误如下 页面报错: No input file ...