.jsp file not running through HTML - java

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.

Related

How getRequestDispatcher will work for Sub-Folder JSP page?

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.

jsp:include causes Servtlet exception app engine

After a lot of debugging I found that every time I include jsp files like:
<jsp:include page="header.jsp">
when I try do do a HTTP request like: /whatever/request I get the following exception:
javax.servlet.ServletException: File "/whatever/header.jsp" not found
The same exception will happen if I try any path instead of /test above for instance /test/test/request or anything.
When I removed all the directives everything is fine. How do I workaround this.
It looks for jsp relative to context path, in your example it looks for jsp stored in /whatever/header.jsp and it is not there, you should access jsp files by writing their full project's path, otherwise it will look for those jsp in the exact folder you are referring to in your url, if it shows error in folder /list/London, and you include jsp like
<jsp:include page="some.jsp"/>
Then it will look for that file in /list/London/, but if you write
<jsp:include page="/some.jsp"/>
It will look for it in your project's root, meaning under /

Getting error running struts2 helloworld program

I m new in Struts2. Creating a hello world program using struts. When I run it got first screen where i put my input but when click on submit button giving following error.
Source of this helloworld example: http://www.tutorialspoint.com/struts_2/index.htm
HTTP Status 404 - /HelloWorldStruts2/hello
type Status report
message /HelloWorldStruts2/hello
description The requested resource (/HelloWorldStruts2/hello) is not available.
Apache Tomcat/6.0.29
Suggest what is the issue?
Got the solution.
In index.jsp there was <form> tag. When I changed it to <s:form> its working fine.
Or change from
<form action="hello">
to
<form action="hello.action">
This is what worked for me, specific to the question. Tomcat 8 was used:
Make sure you have created the classes folder under WebContent\WEB-INF.
In that create the logging.properties file and add the following content to it. (It doesn't matter if the file jumps on its own to Java Resources > Libraries) :-
org.apache.catalina.core.ContainerBase.[Catalina].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].handlers = \ java.util.logging.ConsoleHandler
Then in the location of Tomcat's webapps folder delete your HelloWorldStruts2.war file.
Now follow the site's instructions to Export your project to a new HelloWorldStruts2.war file (remember to overwrite the existing .war file with the same name if it's there).
Again, deploy this file by copying it to your Tomcat directory's webapps folder.
In the browser, go to http://localhost:8080/HelloWorldStruts2/index.jsp again, though I'm not sure it will work for sure this time.
But this time, watch the Tomcat server application's verbose output. You will get some kind of exception like this (leave out Warnings for now):
30-Mar-2014 17:39:29.273 SEVERE [localhost-startStop-7] org.apache.catalina.core.StandardContext.filterStart Exception starting filter struts2 java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:213)
at org.apache.struts2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:102)
...
Seeing this, what I did immediately was copy the commons-lang3-x.y.z.jar to the WebContent\WEB-INF\lib folder, and then exported and deployed the project again.
This time, again the page wasn't showing, so I watched the logs and found out that Tomcat did not explicitly clear the contents of the webapps\HelloWorldStruts2 folder.
After deleting both HelloWorldStruts2 and HelloWorldStruts2.war and refreshing the index.jsp page in the browser, my project did work fine!

Linking Files And Directory Structuring

I'm working on a web project using java/ jsp/ servlets/ html/ css in eclipse tomcat, where everything is in the WebContent folder.
In my jsp files... When I try to include other jsp files (using a link like "/fileName.jsp" in jsp include directive) I can do that successfully.
But When I try to include image files (using a link like "/fileName.jpg" in the <img src=""> tag) nothing happens.
Nothing happens because instead of looking in the WebContent folder for image file it looks in the tomcat home directory, i.e.
Instead of looking at "http ://localhost:port/projectName/..." it looks at "http: //localhost:port/..."
Why does it look at the wrong location only with <img src=""> tags but not in <%# /> tag.
A workaround for this is that I start giving absolute paths "/projectName/..." However doing this means I'm hardcoding project name everywhere. This is what I do not want.
Don't include binary content in an ascii output. Why not just use the img tag? If you need to do something to produce a jpeg, I would use a Servlet.
Because the jsp-Links in the website are getting processed and the image links not. Either change the image path or develop an filter that changes the images'links.
Yes Templar, that could have been a way to solve my problem.
However, I simply changed the Context Root of my project from "Project Name" to "/" in Eclipse. This solved my problem.

Cannot Reach Html File on Google App Engine

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

Categories

Resources