[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Calling jsp from Servlet?

Posted on 2006-04-18
13
Medium Priority
?
388 Views
Last Modified: 2010-04-01
Hello,

My java server book recommends storing the jsp pages inside the web-inf folder. To be sure the jsp pages cannot be directly accessed by the user.

Could I ask to call the jsp from a servlet, do I need to add the jsp in the web.xml. And should the html pages also be placed in the web-inf?

tomcat/webapps/dbtest
tomcat/webapps/dbtest/src/ ----- src contains .java files
tomcat/webapps/dbtest/web/ ------ web contains .jsp and html files
tomcat/webapps/dbtest/web/web-inf/ ---- web-inf contains web.xml
tomcat/webapps/dbtest/web/web-inf/classes/code/ ------- contains the .class files

Thanks
0
Comment
Question by:AntoniRyszard656
  • 6
  • 3
  • 3
  • +1
13 Comments
 

Author Comment

by:AntoniRyszard656
ID: 16480504
Would I use the sendRedirect() method in the servlet's to start the jsp call?

res.sendRedirect();

I thought the alternative forward method was the same as c++ geto() and not recommended.

thanks
0
 
LVL 11

Assisted Solution

by:fargo
fargo earned 100 total points
ID: 16480581
use request dispatcher like follows

RequestDispatcher dispatcher = request.getRequestDispatcher("/relative/path/to/jsp");
dispatcher.forward(request, response);


0
 

Author Comment

by:AntoniRyszard656
ID: 16480836
When copying the jsp files to the web-inf folder do we add the files to the web.xml

And should the html be in the web-inf folder?

Thanks
0
Industry Leaders: 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!

 
LVL 11

Expert Comment

by:fargo
ID: 16480858
When copying the jsp files to the web-inf folder do we add the files to the web.xml
And should the html be in the web-inf folder?

>> Why to do this?? the present structure to keep the jsp files in the folder named web is fine. Why to move them to WEB-INF folder?


0
 

Author Comment

by:AntoniRyszard656
ID: 16480968
I read in my java text moving the jsp files to the web-inf means the user cannot access the .jsp pages directly. Which is good for security reasons.
0
 
LVL 11

Expert Comment

by:fargo
ID: 16480984
well this is all very contradictory. In tomcat if one make the listings option in web.xml to false..then also one cannot access the jsp files. This option of putting jsp files in WEB-INF is all coming now..and cannot be said as a good practise.
0
 

Author Comment

by:AntoniRyszard656
ID: 16481237
It's just in most books I have seen they recommend putting the jsp's in the web-inf folder. At the moment I generally follow the books as a reference to learning servlets.
0
 
LVL 28

Expert Comment

by:rrz
ID: 16483483
>It's just in most books I have seen they recommend putting the jsp's in the web-inf folder    
Please post the names and authors of those books.  
I do share fargo doubts. What code are you hiding ?  Anyway if you really want to put them inside  WEB-INF  then use something like the following to map your JSP file.    

    <servlet>      
                   <servlet-name>mySecureJsp</servlet-name>
                   <jsp-file>/WEB-INF/secure.jsp</jsp-file>
    </servlet>
    <servlet-mapping>
                    <servlet-name>mySecureJsp</servlet-name>
                    <url-pattern>/securedFile</url-pattern>
    </servlet-mapping>
0
 

Author Comment

by:AntoniRyszard656
ID: 16484958
The book was Begining Java Server Pages from wrox press.
0
 
LVL 28

Expert Comment

by:rrz
ID: 16487694
In the book, how did they access the JSPs ?
0
 

Author Comment

by:AntoniRyszard656
ID: 16491296
I think it was in a section of recommendations.

I am not sure if the actually demonstrated how to access the jsp's from the web-inf folder.
0
 
LVL 28

Expert Comment

by:rrz
ID: 16493598
Did you try my method ?
0
 
LVL 35

Accepted Solution

by:
TimYates earned 100 total points
ID: 16497465
When using Struts, I often stick the jsps inside the WEB-INF directory for the reasons stated here...

People go to:

    Whatever.do

And the templated tiled jsp from WEB-INF/pages is returned

If people just look at the component JSPs which make up the complete page there is a chance something I would rather is hidden may sneak through...

Probably won't though, and I don't do it all the time ;-)

And I would only bother when using a framework...  Otherwise you're going to need some sort of dispatcher to handle it all...

Tim
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Will the future of mobile app development include the same trends as those most relevant today? Find out by checking out the 7 trends of the future.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

873 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