Servlet中The requested resource is not available错误

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

1.登录页面index.jsp.

 1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 2 <%
 3 String lUserName = (String)session.getAttribute("iUserName");
 4 %>
 5
 6 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 7 <html>
 8   <head>
 9     <meta charset="utf-8">
10     <title>My JSP ‘index.jsp‘ starting page</title>
11     <meta http-equiv="pragma" content="no-cache">
12     <meta http-equiv="cache-control" content="no-cache">
13     <meta http-equiv="expires" content="0">
14     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
15     <meta http-equiv="description" content="This is my page">
16   </head>
17
18   <body>
19     <%
20         if (lUserName != ""&&lUserName!=null) {
21     %>
22     欢迎光临,<%=lUserName%>
23     <%
24         } else {
25     %>
26     <form name="loginfrm" action="loginserv" method="post">
27      用户名:<input type="text" name="username" value="zhangsan"><br>
28     密码:<input type="text" name="password" value="mm123456"><br>
29     <input type="submit" value="登录">
30     </form>
31  <%
32      }
33  %>
34   </body>
35 </html>

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

 1 package com.kaly.servlet;
 2
 3 import java.io.IOException;
 4 import java.io.PrintWriter;
 5
 6 import javax.servlet.ServletException;
 7 import javax.servlet.http.HttpServlet;
 8 import javax.servlet.http.HttpServletRequest;
 9 import javax.servlet.http.HttpServletResponse;
10
11 public class loginserv extends HttpServlet {
12     public void doGet(HttpServletRequest request, HttpServletResponse response)
13             throws ServletException, IOException {
14         doPost(request, response);
15     }
16
17     public void doPost(HttpServletRequest request, HttpServletResponse response)
18             throws ServletException, IOException {
19         request.setCharacterEncoding("utf-8");
20         response.setContentType("text/html);charset=utf-8");
21         String getUser=request.getParameter("username");
22         String getpassword=request.getParameter("password");
23         PrintWriter pw=response.getWriter();
24         pw.print(getUser);
25     }
26
27 }

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

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

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app version="3.0"
 3     xmlns="http://java.sun.com/xml/ns/javaee"
 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
 6   <servlet>
 7     <description>This is the description of my J2EE component</description>
 8     <display-name>This is the display name of my J2EE component</display-name>
 9     <servlet-name>loginserv</servlet-name>
10     <servlet-class>com.kaly.servlet.loginserv</servlet-class>
11   </servlet>
12
13   <servlet-mapping>
14     <servlet-name>loginserv</servlet-name>
15     <url-pattern>/servlet/loginserv</url-pattern>
16   </servlet-mapping>
17
18 </web-app>

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

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

时间: 2024-08-02 19:19:45

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

The requested resource is not available错误

"HTTP Status 404(The requested resource is not available)"示例 HTTP Status 404(The requested resource is not available)异常主要是路径错误或拼写错误造成的,请按以下步骤逐一排查: 1.未部署Web应用 2.URL输入错误 a.查看URL的IP地址和端口号是否书写正确. b.查看上下文路径是否正确 Project--------Properties------MyElipse

The requested resource is not available.错误

一遇到这种错误下意识地找了半天路径,结果发现没问题 后来才发现原因是eclipse复制项目后引用的还是原来的项目名称 以前用惯了MyEclipse,eclipse改的不彻底 两种方法: 第一种(推荐): 找到项目的.settings文件夹下的org.eclipse.wst.common.component打开 把deploy-name,java-output-path和context-root改回来 然后重点来了,刷新项目(⊙﹏⊙)b 第二种: 右键→Properties→Web Project

【转】The requested resource (/) is not available

HTTP Status 404(The requested resource is not available)异常主要是路径错误或拼写错误造成的,请按以下步骤逐一排查: 1.未部署Web应用 2.URL输入错误 a.查看URL的IP地址和端口号是否书写正确. b.查看上下文路径是否正确 Project--------Properties------MyElipse-----Web----- Web Context-root检查这个路径名称是否书写正确. c.检查一下文件名称是否书写正确. 3.

HTTP Status 404(The requested resource is not available)异常解决

"HTTP Status 404(The requested resource is not available)"示例 HTTP Status 404(The requested resource is not available)异常主要是路径错误或拼写错误造成的,请按以下步骤逐一排查: 1.未部署Web应用 2.URL输入错误 a.查看URL的IP地址和端口号是否书写正确. b.查看上下文路径是否正确 Project--------Properties------MyElipse

The requested resource is not available的解决办法

以"HTTP Status 404(The requested resource is not available)"示例 HTTP Status 404(The requested resource is not available)异常主要是路径错误或拼写错误造成的,请按以下步骤逐一排查: 1.未部署Web应用 2.URL输入错误 a.查看URL的IP地址和端口号是否书写正确. b.查看上下文路径是否正确 Project--------Properties------MyElips

No &#39;Access-Control-Allow-Origin&#39; header is present on the requested resource. Origin &#39;null&#39; is therefore not allowed access.

一.什么是跨域访问 举个栗子:在A网站中,我们希望使用Ajax来获得B网站中的特定内容.如果A网站与B网站不在同一个域中,那么就出现了跨域访问问题.你可以理解为两个域名之间不能跨过域名来发送请求或者请求数据,否则就是不安全的.跨域访问违反了同源策略,同源策略的详细信息可以点击如下链接:Same-origin_policy: 总而言之,同源策略规定,浏览器的ajax只能访问跟它的HTML页面同源(相同域名或IP)的资源. 二.解决方案 常用的解决方案有两种,可以分为客户端解决方案和服务器端解决方案

[转]No &#39;Access-Control-Allow-Origin&#39; header is present on the requested resource.&#39;Ajax跨域访问解决方案

原 https://blog.csdn.net/zhoucheng05_13/article/details/53580683 No 'Access-Control-Allow-Origin' header is present on the requested resource. 什么是跨域访问 举个栗子:在A网站中,我们希望使用Ajax来获得B网站中的特定内容.如果A网站与B网站不在同一个域中,那么就出现了跨域访问问题.你可以理解为两个域名之间不能跨过域名来发送请求或者请求数据,否则就是不安

跨域详解 been blocked by CORS policy: No &#39;Access-Control-Allow-Origin&#39; header is present on the requested resource

跨域问题的原因:浏览器出于安全考虑,限制访问本站点以为的资源. 比如你有一个 网站 127.0.0.1:8080/ , 并且上面挂了一个页面 ,那么在这个页面中 ,你只访问 本站点的 资源不会受到限制,但是你如果访问其他站点,比如  127.0.0.1:8081 的资源就会受到限制. 备注:暂且把  协议,域名,端口都一样的叫做同一个站点. 但是  带有 src 属性的标签可以没有这个 限制,比如 img ,script  等等. 在说说历史,以前的程序前后端不分离, 页面 和 请求接口,在同一

As.net WebAPI CORS, 开启跨源访问,解决错误No &#39;Access-Control-Allow-Origin&#39; header is present on the requested resource

默认情况下ajax请求是有同源策略,限制了不同域请求的响应. 例子:http://localhost:23160/HtmlPage.html 请求不同源API http://localhost:22852/api/values, What is "Same Origin"? Two URLs have the same origin if they have identical schemes, hosts, and ports. (RFC 6454) These two URLs h