2

I tried to create simple servlet project using NetBeans and I've started with login. Login page was done in html and it is stored same as css documment in NetBeans "Web pages" floder (web in directory structure).

Way of storing files in NetBeans

If I try it to view page, all works fine with css included. However if I try to run this file ( shift + F6 ), there is error in browser that says something about fail of redirecting. Error during opening html page

Similar fail is there, if I try to use css file in jsp page. Although I have all html text in jsp page fine and it works if I use plain html page, in jsp page css doesn't work. To solve this problem I tried to use two servers, Glassfish and Apache Tomcat, both are not working. I've just also tried to check several topics that are similar, but description for including css to jsp wasn't working. Next task, that I have there is redirection by response.sendRedirect() function to login page. If I try to redirect to jsp page, it works fine (without css included), but if I try to redirect to html, it doesn't works with same error as is shown above. Same fail happens with not valid address stored as sendRedirect() function parameter. According some answers of this server I have stored html and css file in correct path (please consider the first image in this question).

Referencing a resource placed in WEB-INF folder in JSP file returns HTTP 404 on resource

I think, that web servers simply doesn't know apropriate address for the web page and the css file. Is there some way to add it to web.xml or somewhere else to view the html page? If there is some another failure, how can I fix it? How can I add some external css file to jsp page?

Great thanks for reply!

After ArtyMcFly response added: Thanks for reply. I tried all that you described in your answer. my web.xml looks like that now:

<?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">

 //This is changed code from MartyMcFly   
    <servlet>
    <servlet-name>errorPage</servlet-name>
    <jsp-file>/WEB-INF/errorPage.jsp</jsp-file>
</servlet>
<servlet-mapping>
    <servlet-name>errorPage</servlet-name>
    <url-pattern>/errorPage</url-pattern>
</servlet-mapping>


    <servlet>
        <servlet-name>TestServlet</servlet-name>
        <servlet-class>Controler.TestServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>TestServlet</servlet-name>
        <url-pattern>/TestServlet</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>

and I also changed link in servlet. to

<link rel="stylesheet" type="text/css" href="./css/main.css" />

My css file is stored under Web Pages/css/main.css now. but there is nothing works.

I cannot add screenshots until i will have 10 points. This is some server policy...

PS: Because I have now over 10 points, I've just added some print screen explaining situation.

Community
  • 1
  • 1
nouser
  • 21
  • 1
  • 1
  • 3
  • Sounds like something that should be configurable in settings. "... *that says something about fail of redirecting*" doesn't help a lot. Can you provide the full text of the error message? – mcalex Jul 20 '13 at 09:39
  • If I had ten points of reputation I could send some printscreen. But it looks, that error is not on browser side, because all works during redirecting. Full error in browser is like this: The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to accept cookies. < – nouser Jul 20 '13 at 11:33
  • 1
    upvote to help the rep. If @ArtyMcFly does the same ... – mcalex Jul 20 '13 at 11:56
  • try moving your ErrorPage.jsp page to your WEB-INF folder – Arthur Weborg Jul 20 '13 at 13:04

1 Answers1

0

EDIT removed initial response as it did not help the situation, the following is a working-set-up of css and jsp, both in the Deployment Descriptor(web.xml) and the file structure

I looked at one of my netbean set-ups and my structure looks like the following:

/WEB-INF/jsp/*all my jsp pages*
/css/*css pages*

the Deployment descriptor (web.xml) looks like the following:

<servlet>
    <servlet-name>jsppage1</servlet-name>
    <jsp-file>/WEB-INF/jsp/jsppage1.jsp</jsp-file>
</servlet>
<servlet-mapping>
    <servlet-name>jsppage1</servlet-name>
    <url-pattern>/jsppage1</url-pattern>
</servlet-mapping>

and I included the css within the jsp with the following code:

<link rel="stylesheet" type="text/css" href=" css/main.css" />

So what's going on in the code is it is mapping the URL address /jsppage1 to the file in the WEB-INF folder, and as far as the jsp file is concerned it's being stored then at the root of the project, even though it's in the file structure for the WEB-INF.

Arthur Weborg
  • 8,280
  • 5
  • 30
  • 67
  • Thanks for reply. I've just tried all possibilities that you've just mentioned in my jsp file, but it doesn't work. But I have done it similar way before in plain html and it works. Is there some difference during including css into html and into jsp? Thanks for answer. – nouser Jul 20 '13 at 10:11
  • PS: Mabye there is some html mistake, but I've tried that and also checked some similar questions before I asked there. I am afraid, that server doesnot get, that there is some html and jsp file loaded from some reason, because mentioned redirection to jsp works and to html doesn't, although they are in same location and they have same name (without sufix). – nouser Jul 20 '13 at 10:20
  • I had similar issues when I started trying to figure this stuff out with netbeans haha - I hope the edits help! if the most recent do not, I'm afraid I may have wasted your time and sincerely apologize! I went into netbeans and made a new web-project and added a simple css file to change the background color. at `localhost:8080//jsppage1` it displayed the contents the jsp generated with the background color from the css. – Arthur Weborg Jul 20 '13 at 10:39
  • Could you take a screenshot of the error, or would that be breaking work-rules? – Arthur Weborg Jul 20 '13 at 10:42
  • Answer was added into my question. Thanks for your answer. – nouser Jul 20 '13 at 11:28