wood burning stoves 2.0*
The moose likes JSP and the fly likes How do I run a JSP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How do I run a JSP?" Watch "How do I run a JSP?" New topic
Author

How do I run a JSP?

Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 309
I am creating a web framework with a servlet controller:

I go the idea to forward with RequestDispatcher from "Foundations of JSP Design Patterns". My problem is that my controller is returning "jsp/welcome.jsp" but then the request comes back to the servelet; my web.xml is:

Do I have to do something in web.xml?


Your help will be greatly appreciated,
Alejandro Barrero
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Alejandro Barrero wrote:My problem is that my controller is returning "jsp/welcome.jsp"

Well, we have no idea what "my controller" is. I assume that it's invoked with this line: String view = controller.execute(request, response);

In any case, the next two lines should create a request dispatcher to the referenced JSP and forward to it. Assuming, of course, that the reference is valid.

but then the request comes back to the servelet

What do you mean by that?

Do I have to do something in web.xml?

In order to achieve what? Your post is extremely vague and I really have no idea what you are trying to accomplish or what the problem is.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 309
Thank you Bear Bibeault. I apologize for not being clear. The line: String view = controller.execute(request, response); returns "/jsp/welcome.jsp" which is the page I want to return to the browser. The problem is that forwarding with the RequestDispatcher, the browser is not getting the JSP; what is happening is that the servelet controller is being invoked again and the program is back in the doPost method. What i am trying to achieve is sending to the browser the result of processing the JSP.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

The problem:

<url-pattern>/*</url-pattern>

This says "send every request to my servlet". Every request. Every one. Even for images. Even for stylesheets. Even for HTML. And even for JSPs.

Change it to something like /action/* so that only URL's prefixed with /action/ go to the servlet.
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 309
Yes, the idea is to find a way that the servlet is not called when the URL ends in ".jsp". Actually, The URL I am using is "http://localhost:8080/Front Controller/LoginController" because the web application is called "Front Controller"; if I use <url-pattern>/action/*</url-pattern> I get a 404 error. However It works with <url-pattern>/</url-pattern>.

Now I have a simple web framework; the controllers get the data from the request and the JSPs are populated with JSTL>
 
Consider Paul's rocket mass heater.
 
subject: How do I run a JSP?
 
Similar Threads
Getting Http 404 Error while running Strut Application
Parsing error processing resource path /WEB-INF/struts-config.xml
servlet mapping clarification
Probems in web.xml while migrating from Jboss-5.0.0Beta1 to Jboss-5.1.0GA
FrontMan Commands ?