Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Arranging files under MVC architecture

Posted on 2005-03-27
11
Medium Priority
?
224 Views
Last Modified: 2010-04-01
HI!

I am testing a relatively simple JSP program by using MVC architecture, but I am having “The requested resource (/WEB-INF/hw7/ColorPreferenceMVC4.jsp) is not available.” error.

This is a form that takes input from a user and it is under ~dkim18/hw7/

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Color Preference Form4-HW#7</TITLE>

</HEAD>

<BODY>
<CENTER>
<H1> Color Preference Form 4</H1>

<FORM ACTION="/WEB-INF/hw7/ColorPreferenceMVC4.jsp">
   Background: <INPUT TYPE="TEXT" NAME="bgColor"><BR><BR>
   Foreground: <INPUT TYPE="TEXT" NAME="fgColor"><BR><BR>
   <INPUT TYPE="SUBMIT" VALUE="Submit">
</CENTER>
</FORM>
</BODY>
</HTML>
+++++++++++++
This is JSP page that shows output and it is under dkim18\WEB-INF\classes\hw7

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Color Preference MVC 4-HW#7</TITLE>
</HEAD>
<jsp:useBean id="colorBean" type="coreservlets.ColorBean7" />

<BODY BGCOLOR="<jsp:getProperty name="colorBean" property="bgColor" />"
      TEXT="<jsp:getProperty name="colorBean" property="fgColor" />">
<CENTER>
<H1> Color Preference 4 </H1>
Blah, blah, blah.
 </CENTER></BODY></HTML>
+++++++++++++++++++++++++

this is under ~dkim18\WEB-INF\classes\coreservlets/
package coreservlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ColorPreferenceServlet extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {

    ColorBean7 colorBean = new ColorBean7();
    request.setAttribute("bgColor", colorBean);
      request.setAttribute("fgColor", colorBean);

    String address = "/WEB-INF/hw7/ColorPreferenceMVC4.jsp";
    RequestDispatcher dispatcher =
      request.getRequestDispatcher(address);
    dispatcher.forward(request, response);
  }
}
++++++
thanks,
0
Comment
Question by:dkim18
  • 4
  • 4
9 Comments
 
LVL 92

Expert Comment

by:objects
ID: 13640971
you cannot put jsp's in WEB-INF, files in this directory cannot be accessed externally.
0
 

Author Comment

by:dkim18
ID: 13640986
This is from core Servlets and JSP 2nd edition.
" If your JSP pages only make sense in the context of servlet-generatd data, place the page under the WEB-INF directory. That way, servlets can forward requests to the pages, but clients cannot access them direclty."
0
 
LVL 92

Expert Comment

by:objects
ID: 13640994
sorry didn't notice you were forwarding to it.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dkim18
ID: 13641428
so, why am I having this error?
0
 

Author Comment

by:dkim18
ID: 13641558
If I place ColorPreferenceServlets file under ~dkim18/WEB-INF/classes/hw7/ , I get  "javax.servlet.ServletException: bean colorBean not found within scope" error.
0
 

Author Comment

by:dkim18
ID: 13642145
I changed the form that takes input like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Color Preference Form4-HW#7</TITLE>

</HEAD>

<BODY>
<CENTER>
<H1> Color Preference Form 4</H1>

<FORM ACTION="/~dkim18/servlet/hw7.ColorPreferenceServlets">
   Background: <INPUT TYPE="TEXT" NAME="bgColor"><BR><BR>
   Foreground: <INPUT TYPE="TEXT" NAME="fgColor"><BR><BR>
   <INPUT TYPE="SUBMIT" VALUE="Submit">
</CENTER>
</FORM>
</BODY>
</HTML>

Now, I have two different errors depends on content of ColorPreferenceServlets.

0
 
LVL 1

Expert Comment

by:igoruch
ID: 13644425
Hi,
what do you use - TomCat?  -
 Is your servlet mapped in web.xml?




 
0
 
LVL 92

Expert Comment

by:objects
ID: 13647708
> so, why am I having this error?

Because your form's action is your (hidden) jsp.
you can only forward requests to such pages.
0
 
LVL 92

Accepted Solution

by:
objects earned 600 total points
ID: 13647770
> <FORM ACTION="/~dkim18/servlet/hw7.ColorPreferenceServlets">

You should be defining your servlet mapping in your web.xml
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, the users face difficulty in accessing Outlook 2016 PST files on Windows 10 computer. One of the reasons behind it is the improper functioning of MS Outlook when the user tries to open it. MS Outlook suddenly stops working, or it will not op…
A quick solution showing how to control and open a POS Cash Register Drawer using VBA with MS Access.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question