Getting error running struts2 helloworld program - java

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!

Related

File and links not accessible after generating a .war file with spring boot app

I have a spring boot application that runs very well, But after generating a war file so as I can run the application on separate tomcat server not the embedded one, I am unable to access some pages and files. I have rename the generated war file to mywarfile.war .This qusetion has two separate relate issues.
First issue-Access a linked page
Below is the link inside index.html that will lead to a method that will perform some code then leads to all.html
<button class="btn btn-secondary"> View Welding Product Record </button>
Method
#GetMapping("/all")
public String getAllProducts(Model model){
//.....codes
return "all"
}
Everything works fine with embedded tomcat with spring boot, but when click the link with the war file deployed to separated tomcat server it redirects to http://localhost:8080/all and shows below error.
HTTP Status 404 – Not Found
Type Status Report
Message The requested resource [/all] is not available
Description The origin server did not find a current representation
for the target resource or is not willing to disclose that one exists.
Apache Tomcat/8.5.65
The mywarfile.war is placed on C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\mywarfile.war
But if I type manual on url http://localhost:8080/mywarfile/all I can access the page. What could be the cause of this. And How can I fix it.
Second issue - Access images
I have a background image in my index.html that can be accessed before generating the war file, But after generating the war file and run it on separate tomcat server I cannot see the image.
Below is the code in index.html
<style>
body{background-image: url('/images/ocean.jpg');}
<style>
This is the structure of how I store the images in my project
\src\main\resources\static\images\ocean.jpg
what could be the cause of this and how can I solve it. Thanks in advance

OpenShift Resource Locale Set to en_US - Resources NOT Found

I am moving a Struts 1.3.10 webapp to OpenShift.
To get started I have moved just the login page stuff to OpenShift. It works perfectly on my development machine but on OpenShift, the login page input field labels show like this:
???en_US.label.login???
The labels are in a resource file called MessageResources.properties.
I tried creating a resource file called MessageResources_en_US.properties but it made no difference.
I also tried this:
rhc env-set -a testdb LC_ALL=en_GB.UTF-8
But that made no difference either.
Any ideas?
I know it's something to do with locale...
The solution was to move MessageResources.properties from /src/main/java to /src/main/resources.
Simples...

Why doesn't tomcat see certain folders?

In my tomcat webapps directory I have various projects with servlets in them ..
say named test,beer etc
My question is irrespective of the web.xml or contents when i type localhost:8080/folderName I must be able to view the contents right? but it doesnt work for all folders , for some it says resource not found ,
Example my test folder opens in the browser and my beer folder doesnt , I restarted the browser and tomcat after adding or modifying folders , why can this happen , please explain
My dear friend there is a certain process/configuration/rule that tomcat follows in order to render any web content.It is not some magic happening.
Tomcat has a way of reading web deployments within the /webapp directory.
When we type some URL On the browser tomcat does the following:
Example.
URL : http://localhost:8080/foldername/xyz
Here tomcat takes the part of the URL after http://localhost:8080,that is foldername/xyz.
So here the first part which is foldername means name of the folder present in the /webapps folder.
So reading this tomcat goes inside that folder.Later tomcat is at the mercy of a file called web.xml.All mapping from /foldername/ i.e. /xyz in our case, onwards are present in web.xml.
In your case , if you type http://localhost:8080/foldername/ , tomcat knows that browser refers to webapps/foldername but does not know which resource html/jsp/servlet to forward the request so as to be able to generate a response.
Hence it gives a resource not found exception.
If you want to run the above URL (http://localhost:8080/foldername) then you need to configure a <welcome-file-list> tag in the web.xml file.
So for the folders which are working in your case with the above URL, just open their web.xml file and you shall find the <welcome-file-list> tag.
Actually this is what happened
I had a folder test which had some files (NO WEB-INF) , tomcat listed its contents on typing localhost:8080/test
My other folder beer had a WRONG WEB-INF web.xml configuration
So the following is clear to me now
Without a WEB-INF folder and web.xml tomcat will just list the contents of the directory but when you have a WEB-INF and web.xml and something is wrong in them it doesnt even list the directory contents .
Just my understanding of it .
Thanks!

ActiveWeb web application does not run under Jetty

I have created sample web application, packaged it into WAR, then put it into webapps folder into jetty. And it does not work.
Proof, windows from top to bottom:
1) The content of GreetingController.java
2) The compiled file is present inside WAR file in appropriate place
3) The web application is working, it's name is recognized (folder content displayed)
4) Controller is not working and it's name is not recognized
What else to check?
UPDATE
My WAR file: https://www.sendspace.com/file/mb94jt
I think you are missing something in your app. The page you are referring is just a guide to help understand how the framework works. For complete simple examples, please refer to:
https://github.com/javalite/activeweb-bootstrap - this is a simple app with Bootstrap and no database support
https://github.com/javalite/activeweb-lessc - simple app without database, but with Less instead of CSS
https://github.com/javalite/activeweb-simple - simple ActiveWeb + ActiveJDBC webapp (CRUD)
Here is the Getting Started page: http://javalite.io/getting_started_activeweb
hope it helps

build-impl.xml:1025: The module has not been deployed. (Wicket)

I have been working on a Java web application using wicket framework on Netbeans 7.2 and out of a sudden I encountered this problem. I tried cleaning the build-impl.xml then restarting the IDE and I should say I have fairly low knowledge on this. Can someone please tell me why it is giving an error and how I can fix that?
The lines 1024, 1025 and 1026 are :
<target if="netbeans.home" name="-run-deploy-nb">
<nbdeploy clientUrlPart="${client.urlPart}" debugmode="false" forceRedeploy="${forceRedeploy}"/>
</target>
The error message says :
nbproject/build-impl.xml:1025: The module has not been deployed.
See the server log for details.
BUILD FAILED (total time: 4 seconds)
I came up with a solution by myself, I cloned the project and changed the project's directory name back to original, that worked fine for me. But it seems to have a better and proper solution, though.
/* START BY RESTARTING YOUR GLASSFISH SERVER */
1-add DBMS(ex:oracle,MySQL,MsSQL..) jdbc connector jar to domain
"glassfish directory/domain/{yourDomain}/lib"
2-add connection pool in glassfish server "JDBC-->ConnectionPool"
3-add your JNDI "JDBC-->jdbc ressource"
4-Test connection
5-add additional properties
IF YOU HAVE NO PASSWORD ON YOUR DATABASE ACCOUNT YOU CAN EASILY
6- glassfish/config/domain.xml change password value to "" in your jdbc-connection-pool
may its so late but the response useful for others so : Sometimes, when you don't specify a server or servlet container at the creation of the project, NetBeans fails to create a context.xml file.
In your project under Web Pages, create a folder called META-INF.
Do this by right mouse button clicking on Web pages, and select:
New->Other->Other->File Folder
Name the folder META-INF. Case is important, even on Windows.
Create a file called context.xml in the META-INF folder.
Do this by right mouse button clicking on the new META-INF folder, and select:
New->Other->XML->XML Document
Name it context (NetBeans adds the .xml) Select Well-formed Document Press Finish
Edit the new document (context.xml), and add the following:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/app-name"/>
Replace app-name with the name of your application.
Now your in-place deployment should work. If not, make sure that the file can be read by everyone.
The context.xml file is specific to Tomcat. For more information about that file, see the Tomcat documentation at tomcat.apache.org.

Categories

Resources