自己为了测试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. 【kate整理】matlab求商,求余数

    a/b=q...r   a=b*q+r  r为余数 fix(a/b)    求商rem(a,b)  求余数还可以 mod(a,b) 两者的区别是余数的符号,rem与a相同,而mod与b相同 例1: & ...

  2. web前端从0开始--1

    博主以前没接触过web前端,最近刚开始学习. 在学习的同时,希望能不断整理总结.于是便有了此博客. 博主技术浅薄,并且第一次写此类博客,希望各位大牛能多多保函. 好了废话不多说了,开始正文. web前 ...

  3. http状态消息

    1-5状态码了解 1XX 表示信息(消息) 2XX 表示成功 3XX 表示重定向 4XX 表示请求错误 *** 5XX 表示服务端错误 常见状态码 200 请求成功 一切正常 301 重定向,修改后的 ...

  4. 利用calc计算宽度

    width:calc(100% - 40px)可用 + - * / 进行计算(ie9+) 注:计算符号前后必须跟上空格.

  5. js日期重写

    Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d ...

  6. 【分析】Parcelable的作用

    一.介绍 1.Parcelable是一个接口,可以实现序列化. 2.序列化的作用体现在:可以使用Intent来传递数据,也可以在进程建传递数据(IPC). 3.Parcelable在使用的时候,有一个 ...

  7. 使用 IDEA + Maven + Git 快速开发 JAVA或者Web 应用(转)

    0-0 前言 最近和同事做爬虫,其中我主要遇到的问题是:同事在github上放了爬虫demo让我自己去下载,然后自己能搭好环境让整个项目跑起来去抓51job找工作数据.git上克隆一个项目下来,项目是 ...

  8. iOS技术博客(文摘)链接地址

      objc系列译文(5.1):认识 TextKit 手把手教你配置苹果APNS推送服务 如何使用iOS Addressbook UIApplication深入研究 GCD倒计时 那些不能错过的Xco ...

  9. vim 分屏显示

    我用vim打开一个文件后,想同时打开另一个文件,就像windows中打开两个记事本一样,因此需要分屏显示 首先用vim打开一个文件 vim file1 输入命令[Esc] :sp file2 分屏打开 ...

  10. jquery省市联动,根据公司需求而写

    //author:guan //2015-05-25 //省市联动 //实用说明,页面引用如下js //<script src="../js/jquery-1.6.3.min.js&q ...