Use jsp:forward to forward to another page - java

I am learning about jsp and servlet. In an online tutorial, he used <jsp: forward> to move to another jsp page.
<jsp:forward page="home"></jsp:forward>
The directory tree: (eclipse)
The directory tree
I don't understand why when I run the program, the index.jsp file in the home directory is run. Why is he using <jsp: forward page = "home"> </ jsp: forward> instead of <jsp: forward page = "/ WEB-INF / views / home / index.jsp "> </ jsp: forward>
Can someone please explain me the using the relative url in web project.
Thank you so much !

Related

.jsp file not running through HTML

I have a file hello.jsp. Its working fine in tomcat when I type localhost:8080/hello.jsp in the url tab of the browser.
However when I try to call the file from html like this:
<form action="hello.jsp">
I get the error
"Your file was not found ,It may have been moved or deleted"
and no page is loaded. How can I run my file through HTML page. I am having same problem with servlet too.

Intellij IDE JSP path resolving [duplicate]

This question already has an answer here:
How specify path to .JSP file for request.getRequestDispatcher()?
(1 answer)
Closed 6 years ago.
I have a servelet called RegisterUser mapped as /register this servelet includes a jsp file called register.jsp . here is the structure of the project :
inside the servelet this code cannot find the jsp file :
RequestDispatcher view = request.getRequestDispatcher(registerView);
and the content of registerView is :
private static final String registerView = "../web/WEB-INF/views/Register.jsp";
It worked fine on eclipse but when I switched to Intellij it shows that the file cannot be found .
Liferay has a somewhat strange layout for it's web-inf and html folders. In Eclipse I never really code path completion to work well in JSPs because it always looked at the wrong spot for files. In IntelliJ I just setup different facets that will help the IDE help me. Here is an example. I have a facet called WEB-INF. In Liferay, when you reference a file in WEB-INF (tagfiles are a GREAT example here) you do it like this:
<%# taglib prefix="showMore" tagdir="/WEB-INF/tags/wj/showmore" %>
The problem there is that by default, the IDE wants to autocomplete like this:
<%# taglib prefix="showMore" tagdir="/docroot/WEB-INF/tags/wj/showmore" %>
I simply made a web facet and said that when I type /WEB-INF I really want you to look at /docroot/WEB-INF. This small change saves me so much headache throughout the day. I also did the same thing with /html instead of /docroot/html.
You know how in eclipse when you go to an init.jsp file in the ext environment it always freaks about the init.jsp includes from portal because it can't find it? I once again used a web facet (called portal-web) and I linked / to /liferay/builds/4.3.x/portal-web/docroot. Now when I say:
<%# include file="/
right there it starts autocompleting. It lists out everything in both portal-web and ext-web for me, because I have access to both inside Liferay! Doing this then:
<%# include file="/html/common/init.jsp" %>
it's a problem, I can even click init.jsp and press ctrl (cmd) + b and it will jump me right into the init file in portal.
I tend to run IntelliJ with one "Module" and two "Content Roots". One content root is portal, the other is ext. The plus here is that the debugger knows about the portal source files, and I can easily jump between jsp files as well.
Resource Link:
Why I use IntelliJ instead of Eclipse?

ROOT.war file on Openshift

I've deployed Test.war file on Openshift and my application test-sliwa.rhcloud.com/Test run OK. When I deploy ROOT.file application test-sliwa.rhcloud.com doesn't run in right way - first page is ok, but when I try to link to other pages I have 404 error.
The problem was in source code in links declared. It's better to declare domain-relative URL like:
<a href="<%= response.encodeUrl(request.getContextPath() + "/Controller?action=login") %>">
instead of:
<a href="Test/Controller?action=login")">}
in index.jsp file.

xml file not found in ear file after running ant build [duplicate]

This site doesn't allow user to ask technical questions to their tutorial which I believe is broken:
http://www.mkyong.com/misc/how-to-use-mkyong-tutorial/
I'm using:
maven: 3.2.1
tomcat 7
java 1.7
Eclipse: Luna Release (4.4.0)
I'm getting this message:
WARNING: Could not find action or result
There is no Action mapped for namespace [/] and action name [] associated with context path [/Struts2Example]. - [unknown location]
I can never get to the login.jsp page unless I enter the full url. But even then, when I click on the submit button, it doesn't go to the welcome_user.jsp page either.
Can someone tell me how I can fix this and get this Hello World example to work in using Eclipse?
If you follow the tutorial, which is linked to the page Struts 2 Hello World Example, and done everything till p. 7 then you should Run it as is written
In Struts2, you can access the action class directly with a suffix of
.action.
http://localhost:8080/Struts2Example/User/Login.action
If you tried to access application as
http://localhost:8080/Struts2Example
you will get a message and 404 error code is returned to the browser.
WARNING: Could not find action or result There is no Action mapped for
namespace [/] and action name [] associated with context path
[/Struts2Example]. - [unknown location]
The workaround is to add the file to the web root folder that will redirect a browser to the correct location.
index.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=User/Login.action">
</head>
<body>
<p>Loading ...</p>
</body>
</html>
Also modify web application deployment descriptor to include this file name to the welcome files list.
web.xml:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
That's it, if you are looking for the Hello World tutorial, you should use these references:
Hello World
Hello World Using Struts 2
How To Create A Struts 2 Web Application
Create Struts 2 Web Application Using Maven To Manage Artifacts and To Build The Application

how to call a jsp which is in a different WAR file

I have a click here link on a jsp. On clicking, another jsp which is in another WAR file has to be called. I'm using JSF frmework.
Can anyone help me out please....!!!
How about just anchor tag ?
Click Me
JSF
<h:outputLink value="http://someserver:port/app2/some.jsp"><h:outputText value="Click Me"/></h:outputLink>

Categories

Resources