I am using getRequestDispatcher() function for passing notification message to a jsp page after perform any operation in JSP Servlet. But the method works fine when i pass message to a root directory JSP page But it doesn't work for a sub folder directory file in the same project.
This Works Fine (for root directory Page) -
request.setAttribute("Message", "Message Text" );
getServletContext().getRequestDispatcher("/Index.jsp").forward(request,response);
But its not work(for sub-folder directory Page) -
**request.setAttribute("Message", "Message Text" );
getServletContext().getRequestDispatcher("/Folder/Index.jsp").forward(request,response);**
I attached an image of my project structure-
I want to send message with getRequestDispatcher() to a page whic is under admin folder. but the Response URL stack at http://localhost:8080/ALPMS/Servlet
What should i have to change in ?
Thanks in Advance.
Related
I have a web App running in liberty that utilizes jsf, made in eclipse. I am attempting to place my rendered pages (.xhtml files) in subdirectories in order to organize the URL paths.
Example:
http://1sy:9011/Batch/main.xhtml (Not actual Links. Just an Example)
To look like this: http://1sy:9011/Batch/subdirectory/main.xhtml (Example: Not a link)
where subdirectory is a folder within the webcontent directory. The problem with this is that if I use a bean method to call the page in the sub-directory, any method within that page that calls a page outside of this sub-directory will no longer worked when an input within a form is activated on that page within the sub-directory. How can I render pages outside of the sub-directory once I have called a page within it? I will place sample code with an explanation below.
public String viewGroups(){
return "subdirectory/viewgroups";
}
This method will render the .xhtml viewgroups, which is in the subdirectory(folder) "subdirectory" within the webcontent folder, but if I press a button on view groups that calls the following method:
public String editSelectedGroup(){
return "editgroup";
}
editgroup.xhtml will not be called. editgroup.xhtml is in the root of the webcontent directory, back outside of the subdirectory.
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.
Im trying to read files(xml, images) from src/main/resources. But it doesnt work.My resources folder is Source folder. For example, when i m trying to read log4j.xml tomcat looking for it in C:/bin... And i also cant read images from resources. I can read it only from webapp. I ve read, that tomcat automatically replace files from resources to webinf, but i think that it doesnt work in my case.
Please, help. I dont have any idea.
Even if the png is added to the WEB-INF folder it wouldn't be accessible from the JSP page in your case.
On runtime a JSP page renders into a servlet that return HTML code in the response. Then a browser will parse your tag <img src="/Pajero.png" ... /> and send a request onto YOUR_HOST/Pajero.png url to access the image and get the error code 404, because content of the WEB-INF folder is not accessible for a client side in a java web application.
Perhaps it will be better to place images on the webapp folder at your case.
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("log4j.xml").getFile());
You can use something like this to get resources from classpath.
Regards
I have servlet that dispatches jsp files for a loggin project, the logic works fine but I am not getting the right jsp, but an error instead:
if (user.isValid())//isValid UserDAO
{
HttpSession session = request.getSession(true);
session.setAttribute("currentSessionUser",user);
response.sendRedirect("/Logggedin.jsp"); //logged-in page
//System.out.println("You are logged in");
}
else
{
response.sendRedirect("/InvalidLogin.jsp"); //error page }
//System.out.println("You are not logged in");
}
Note that my base path is /ClassGrading/*, I tried both paths: ClassGradking/Loggedin.jsp and the one above, within the index.jsp page I have the following code:
<form action="LoginServlet">
404 means file not found.I am not aware of the location of Logggedin.jsp and InvalidLogin.jsp
But I think you should do response.sendRedirect("Logggedin.jsp"); //logged-in page
and response.sendRedirect("InvalidLogin.jsp"); //error page }
Remove the /
From the OP's comment
The jsp and html files should be outside WEB-INF folder
Lets say your project name is test, then all class files(.class) files will be inside WEB-INF/classes.
All jar files should be inside WEB-INF/lib.Web.xml should be inside WEB-INF and all jsp/html files should be outside WEB-INF
Apache tomcat file deployement
I have an Eclipse Java project, and I added a "folder" off of the root called "webfiles". I then proceeded to create a file called form.html. Once I run the project locally or publish it, I cannot reach the .html file. I get a Not_Found error.
Is it possible in Google App Engine to use HTML files (other than index.html) and where do I have to place them in the project to access them by a browser? What path should I use in the browser.
You need to add include path="/**.html" " in your static files definition in appengine-web.xml else html files other than index.html would not even be uploaded.
If you have /war/webfiles/form.html in your project than path to acces it from browser:
http://your_app_name.appspot.com/webfiles/form.html
To make reference from other jsp pages use:
link to form