Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6031805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:14:22+00:00 2026-05-23T05:14:22+00:00

I’m trying to send some thing to a servlet but i get this Etat

  • 0

I’m trying to send some thing to a servlet but i get this

    Etat HTTP 404 - /pdfreader/Services%20Web%20avec%20J2EE%20et%20.NET.pdf

--------------------------------------------------------------------------------

type Rapport d''état

message /pdfreader/Services%20Web%20avec%20J2EE%20et%20.NET.pdf

description La ressource demandée (/pdfreader/Services%20Web%20avec%20J2EE%20et%20.NET.pdf) n'est pas disponible.

I invoke it from my JSP like this

<a href="/pdfreader/<%=filename/*le nom d'un fichier pdf par exemple (jsp.pdf)*/ %>"><%=bookName %> </a>

and my servlet code is

package com.search.ts;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLDecoder;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class pdfreader
 */
@WebServlet("/pdfreader")
public class pdfreader extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public pdfreader() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
          String filename = URLDecoder.decode(request.getPathInfo(), "UTF-8");
            //filename= request.getParameter("err");
            //String filename =(String) request.getAttribute("linkbook");
            File file = new File("F:/fichiers/", filename);

            response.setContentType(getServletContext().getMimeType(file.getName()));
            response.setContentLength((int) file.length());
            response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\"");

            BufferedInputStream input = null;
            BufferedOutputStream output = null;

            try {
                input = new BufferedInputStream(new FileInputStream(file));
                output = new BufferedOutputStream(response.getOutputStream());

                byte[] buffer = new byte[8192];
                int length;
                while ((length = input.read(buffer)) > 0) {
                    output.write(buffer, 0, length);
                }
            } finally {
                if (output != null) try { output.close(); } catch (IOException ignore) {}
                if (input != null) try { input.close(); } catch (IOException ignore) {}
            }
    }

}

when i create the servlet and the jsp i dont get any web.xml in web-inf (i use eclipse)

so i try to create one

<?xml version="1.0" encoding="UTF-8"?>

<web-app>
<welcome-file-list>
<welcome-file>/vieu/indexS.jsp</welcome-file>
</welcome-file-list>
<servlet>
<javaee:description></javaee:description>
<javaee:display-name>pdfreader</javaee:display-name>
<servlet-name>pdfreader</servlet-name>
<servlet-class>pdfreader</servlet-class>
<jsp-file>/vieu/indexS.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>com.search.ts.pdfreader</servlet-name>
<url-pattern>/pdfreader/*</url-pattern>
</servlet-mapping>
</web-app>

Anyone know why that don’t work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:14:23+00:00Added an answer on May 23, 2026 at 5:14 am

    All that French is extremely confusing. But at least a HTTP 404 error is clearly self-explaining: it just means that the request URL is plain wrong or that the resource (servlet) failed to startup.

    There are several potential problem causes:


    First, the link:

    <a href="/pdfreader/<%=filename%>"><%=bookName %></a>
    

    The leading slash / in the URL makes it relative to the domain root. So when your JSP runs on http://localhost:8080/contextname/vieu/indexS.jsp, then this URL actually points to http://localhost:8080/pdfreader/name.pdf. But you want it to be http://localhost:8080/contextname/pdfreader/name.pdf! So fix it accordingly

    <a href="${pageContext.request.contextPath}/pdfreader/<%=filename%>"><%=bookName %></a>
    

    Second, the servlet declaration:

    @WebServlet("/pdfreader")
    

    This is completely wrong. You need to annotate it as follows:

    @WebServlet(urlPatterns={"/pdfreader/*"})
    

    Third, the web.xml is missing the Servlet API version declaration which causes that the container falls back to the least compatibility modus and thus the new Servlet 3.0 @WebServlet annotation won’t work anymore. Fix it accordingly:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app 
        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"
        id="WebApp_ID" version="3.0">
    
        <!-- Config here -->
    </web-app>
    

    and remove the <servlet> and <servlet-mapping> declarations from your web.xml. Those are not necessary with (a proper!) @WebServlet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.