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 6979495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:53:40+00:00 2026-05-27T17:53:40+00:00

Using Netbeans I’m setting up a MVC-powered website on localhost. I’ve set up the

  • 0

Using Netbeans I’m setting up a MVC-powered website on localhost. I’ve set up the controller as a servlet which points client requests to the relevant JSP pages.

When I try to access the JSP files directly I have no problems, but when I try via the url patterns set in the controller servlet I get blank pages. I know the pointing is working because if I request a url pattern that hasn’t been named in the controller servlet I get a 404 not found error.

Here is the code for the servlet template file:

 public class ControllerServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
    String userPath = request.getServletPath();
    if (userPath.equals("/book")) {   
    }
    String url = "/WEB-INF" + userPath + ".jsp";
    request.getRequestDispatcher(url).forward(request, response);
}


@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

    String userPath = request.getServletPath();
    if (userPath.equals("/profile")) {
    } else if (userPath.equals("/updates")) {
    } else if (userPath.equals("/mybooks")) {
    }
    String url = "/WEB-INF/view" + userPath + ".jsp";
    request.getRequestDispatcher(url).forward(request, response);
}

 }

The ControllerServlet file contains an additional line on top of the standard HTTPServlet code:

@WebServlet(name = "ControllerServlet", loadOnStartup = 1, urlPatterns = {"/profile", "/mybooks", "/updates", "/book"})

XML file:

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

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>
<context-param>
    <description>The relative path to images of book covers.</description>
    <param-name>coversImagePath</param-name>
    <param-value>img/bookCovers</param-value>
</context-param>
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
</servlet>
<servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
        <param-name>config</param-name>
        <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
        <param-name>debug</param-name>
        <param-value>2</param-value>
    </init-param>
    <init-param>
        <param-name>detail</param-name>
        <param-value>2</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<jsp-config>
    <jsp-property-group>
        <description>header and footer settings</description>
        <url-pattern>/index.jsp</url-pattern>
        <url-pattern>/WEB-INF/view/*</url-pattern>
        <url-pattern>/book.jsp</url-pattern>
        <include-prelude>/WEB-INF/jspf/header.jspf</include-prelude>
        <include-coda>/WEB-INF/jspf/footer.jspf</include-coda>
    </jsp-property-group>
</jsp-config>
<resource-ref>
    <description>Connects to database for bookshelves application.</description>
    <res-ref-name>jdbc/bookshelves</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
  • 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-27T17:53:41+00:00Added an answer on May 27, 2026 at 5:53 pm

    Put the JSP in /WEB-INF folder. It’ll fix 2 things:

    1. You won’t get a blank page.
    2. You won’t be able to access the JSP directly (which is correct and desired behaviour!)

    You need to fix 2 other problems not directly related to the concrete problem:

    1. Never suppress exceptions unless you know what you’re doing. Remove that try-catch.
    2. Never ignore server logs. The forward() did throw an exception.

    Additional benefit is that you won’t get a blank page anymore and thus will see your mistake immediately in flavor of a self-explaining exception (only if you didn’t override the server default HTTP 500 error page by some custom <error-page> which in turn doesn’t show anything of the exception).

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

Sidebar

Related Questions

I am using NetBeans' GUI Designer to create some JDialog s, which I then
I'm using netbeans to generate web service client in my application. And my program
Using NetBeans, I have generated Hibernate mapping files and set of POJOs. I have
Using Netbeans 6.9.1 my unit tests pass without issue. Using junit (4.8.2, which seems
im using netbeans with svn. i've checked out a project and then i used
im using netbeans for svn. i open a project in netbeans and then i
I'm using NetBeans, trying to change the familiar Java coffee cup icon to a
I'm using NetBeans 6.5 for developing PHP and I have xdebug setup. Is there
Since I've started using NetBeans, I've learned of some powerful ways to abstract away
I am using NetBeans for PHP 6.5. In my code I frequently use the

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.