The requested resource is not available error in the servlet

Source: Internet
Author: User

In order to test the servlet, I wrote a simple login program with MyEclipse2015.

1. Login Page index.jsp.

1 <%@ Page Language="Java"Import="java.util.*"pageencoding="Utf-8"%>2 <%3 StringLusername= (String) Session.getattribute ("Iusername");4 %>5 6 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en">7 <HTML>8   <Head>9     <MetaCharSet= "Utf-8">Ten     <title>My JSP ' index.jsp ' starting page</title> One     <Metahttp-equiv= "Pragma"content= "No-cache"> A     <Metahttp-equiv= "Cache-control"content= "No-cache"> -     <Metahttp-equiv= "Expires"content= "0">     -     <Metahttp-equiv= "keywords"content= "Keyword1,keyword2,keyword3"> the     <Metahttp-equiv= "description"content= "This is my page"> -   </Head> -    -   <Body> +     <% -         if(lusername! )= ""&&lusername!=NULL) { +     %> AWelcome,<%=Lusername%> at     <% -         } Else { -     %> -     <formname= "Loginfrm"Action= "Loginserv"Method= "POST"> -User name:<inputtype= "text"name= "username"value= "Zhangsan"><BR> -Password:<inputtype= "text"name= "Password"value= "mm123456"><BR>  in     <inputtype= "Submit"value= "Login"> -     </form> to  <% +      } -  %> the   </Body> * </HTML>

2. Use the template to write a servlet program Loginserv.java.

1  PackageCom.kaly.servlet;2 3 Importjava.io.IOException;4 ImportJava.io.PrintWriter;5 6 Importjavax.servlet.ServletException;7 ImportJavax.servlet.http.HttpServlet;8 Importjavax.servlet.http.HttpServletRequest;9 ImportJavax.servlet.http.HttpServletResponse;Ten  One  Public classLoginservextendsHttpServlet { A      Public voiddoget (httpservletrequest request, httpservletresponse response) -             throwsservletexception, IOException { - DoPost (request, response); the     } -  -      Public voidDoPost (httpservletrequest request, httpservletresponse response) -             throwsservletexception, IOException { +Request.setcharacterencoding ("Utf-8"); -Response.setcontenttype ("text/html); Charset=utf-8"); +String Getuser=request.getparameter ("username"); AString getpassword=request.getparameter ("Password"); atPrintWriter pw=Response.getwriter (); - Pw.print (getUser); -     } -  -}

This is a very simple program, after receiving the request, the user name to print out.
3. Problem running: The requested resource is not available.

4. Find inquiries, not resolved. Later view Web. Xml.

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Web-appversion= "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 EE component</Description>8     <Display-name>This is the display name of my EE component</Display-name>9     <Servlet-name>Loginserv</Servlet-name>Ten     <Servlet-class>Com.kaly.servlet.loginserv</Servlet-class> One   </servlet> A  -   <servlet-mapping> -     <Servlet-name>Loginserv</Servlet-name> the     <Url-pattern>/servlet/loginserv</Url-pattern> -   </servlet-mapping> -  - </Web-app>

Because these are automatically generated, there is no thought of a problem. However, remember to write this program when the <url-pattern> node just before the <servlet-name> node content more than a "/", try to change it to/loginserv, restart the service run page. Some normal.

Summary: This should be one of the ways to solve this problem.

The requested resource is not available error in the servlet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.