OGNL and wildcards working in tiles definitions with struts2-tiles-plugin? - struts2

I want Tiles to resolve ognl from the struts2 value stack. How to do this?
Using tiles 2.2.2 (although if a later version such as 3 could be used that is fine)
Here it mentions the new feature:
http://tiles.apache.org/2.2/framework/whats-new.html
Here it shows how to implement it: http://tiles.apache.org/2.2/framework/tutorial/advanced/el-support.html#OGNL_Support
But I'm not certain how to go about that in my project. Does anyone have tiles3 working in their struts2 project? I remember reading about some way to turn on all new features in tiles 3 by default but I can't find a link to that page.
If configuration can be done in anyway with spring that is fine (if that helps, if not it is not an issue).

I love the tiles tempate system because it is simple and straight forward, with Tiles 2.2.2 you can have wild card support to push your struts2 conventions right into the template system and now there is OGNL too!
Steps to add tiles 2.2.2 with OGNL support within tiles (Currently using Struts 2.3.1.2):
1) Add the struts2-tiles-plugin
2) Add the tiles 2.2.2 jars including the jars which add ognl support. Assumes maven: ALL group ids are: org.apache.tiles ALL versions are 2.2.2, the following are artifact ids :
tiles-api
tiles-core
tiles-extras
tiles-jsp
tiles-ognl
tiles-servlet
Also needed to add the following:
log4j, log4j, 1.2.14 (Should already be part of the basic setup: http://struts.apache.org/2.x/docs/create-struts-2-web-application-using-maven-to-manage-artifacts-and-to-build-the-application.html)
slf4j-api, org.slf4j, 1.6.4
slf4j-simple, org.slf4j, 1.6.4
By using the org.apache.tiles.extras.complete.CompleteAutoloadTilesListener you get Wild Cards, EL, OGNL, MVEL support in your tiles.xml
Example web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>org.apache.tiles.extras.complete.CompleteAutoloadTilesListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
struts.xml for a demo: The demo uses OGNL from struts to display a hard coded greeting message. Three action mappings exist "", "test", and "package/*" the value that follows the slash will be used by tiles to set a new title. A very trivial example but does show some useful features.
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.ui.theme" value="simple" />
<constant name="struts.enable.SlashesInActionNames" value="true" />
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<package name="basicstruts2" namespace="" extends="tiles-default">
<result-types>
<result-type name="tiles" default="true" class="org.apache.struts2.views.tiles.TilesResult"/>
</result-types>
<action name="/**" class="com.kenmcwilliams.tiles.action.Test">
<result>{1}</result>
</action>
</package>
</struts>
tiles.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition name="baseLayout" template="/WEB-INF/content/tiles/template.jsp">
<put-attribute name="title" value="Default Title"/>
<put-attribute name="header" value="/WEB-INF/content/tiles/header.jsp"/>
<put-attribute name="body" value="/WEB-INF/content/tiles/body.jsp"/>
<put-attribute name="footer" value="/WEB-INF/content/tiles/footer.jsp"/>
<put-attribute name="variable" expression="OGNL:greeting"/>
</definition>
<definition name="test" extends="baseLayout">
<put-attribute name="title" value="Test Title"/>
</definition>
<definition name="WILDCARD:package/*" extends="baseLayout">
<put-attribute name="title" value="{1}" type="string"/>
</definition>
<definition name="" extends="baseLayout">
</definition>
</tiles-definitions>
/WEB-INF/content/tiles/body.jsp
<div>
This is the default body.
</div>
/WEB-INF/content/tiles/footer.jsp
<div>
This is the default footer.
</div>
/WEB-INF/content/tiles/header.jsp
<div>
This is the default header.
</div>
/WEB-INF/content/tiles/template.jsp
<%#taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%#taglib prefix="s" uri="/struts-tags"%>
<%#page contentType="text/html" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><tiles:insertAttribute name="title"/></title>
</head>
<body>
<tiles:insertAttribute name="header"/>
<tiles:insertAttribute name="body"/>
<tiles:insertAttribute name="footer"/>
<tiles:insertAttribute name="variable"/>
</body>
</html>
Test.java Action
package com.kenmcwilliams.tiles.action;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Map;
import java.util.logging.Logger;
import org.apache.struts2.interceptor.SessionAware;
public class Test extends ActionSupport implements SessionAware{
private static final Logger log = Logger.getLogger(Test.class.getName());
#Override
public String execute(){
log.info("Test execute");
return SUCCESS;
}
private String greeting = "Hello, World from Action!";
public String getGreeting(){
return greeting;
}
#Override
public void setSession(Map<String, Object> session) {
session.put("greeting", "Greetings from session!");
}
}
That should now be enough to get tiles working for your application.

Related

Issue while upgrading to struts version 2.5.17

I am trying to upgrade struts version from 2.3.35 to 2.5.17 but I encountered an issue as below:
java.lang.NullPointerException
at com.opensymphony.xwork2.util.fs.StrutsJarURLConnection.getInputStream(StrutsJarURLConnection.java:170)
at com.opensymphony.xwork2.util.fs.JarEntryRevision.needsReloading(JarEntryRevision.java:84)
at com.opensymphony.xwork2.util.fs.DefaultFileManager.fileNeedsReloading(DefaultFileManager.java:65)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.needsReload(XmlConfigurationProvider.java:428)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.needsReload(StrutsXmlConfigurationProvider.java:163)
I have been using this guide to migrate to struts version 2.5.17:
https://cwiki.apache.org/confluence/display/WW/Struts+2.3+to+2.5+migration
I suspect it to be issue with tiles.
I have upgraded all struts related jar to version 2.5.17 including struts2-tiles-plugin. I have also upgraded all tiles related jars to 3.0.7.
Also I have removed the Xwork-core jar as from 2.5 xwork being merged to struts2-core jar.
Am I doing anything wrong.
Please note: I have not done any code changes as of now. The code works perfectly with struts version 2.3.35. But as soon as I have upgraded the struts version along with tiles version I started getting this issue.
Can some one please suggest If I am doing anything wrong?
Yes, there are supposed to be errors without code changes.
I don't think you are doing something wrong.
After adding the new .jars and removing the old ones it will only work when the code is compliant with the new framework.
Code changes would be:
.xml
Add the following <code> to web.xml.
<filter>
<filter-name>struts2</filter-name>
<filter-class> org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
Change struts-config.xml to struts.xml and make following changes:
You can remove struts-config.xml completely and use annotations instead of .xml file.( since struts 2.5.17 )
<?xml version="1.0" encoding="ISO-8859-1" ?> <!-- change to UTF-8 -->
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd "> <!-- change to struts-2.5.dtd -->
<struts-config> <!-- change to <struts> -->
<!-- add <include file="struts-default.xml"/> -->
<form-beans>
<form-bean name="MyClassForm" type="forms.MyClassForm">
</form-bean>
</form-beans>
<action-mappings> <!-- change to <package name="hello-default" extends="struts-default"> -->
<action path="/MyClass" name="MyClassForm" type="actions.MyClassAction"
validate="false">
<action name = “MyClass” class = “actions.MyClass”>
<forward name="success" path="/Index.jsp"/>
<result> /Index.jsp </result>
</action>
</action>
</action-mappings> <!-- change to </package> -->
<message-resources parameter="resources"/>
</struts-config> <!-- change to </struts> -->
.java
Remove ActionForm.java files.
Properties are included in ActionSupport class which our Action class is supposed to extend.
Change Action.java
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class MyClassAction extends Action // change to ActionSupport {
//fields are now a property of the ActionSupport class
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// change to public String execute() throws Exception {
MyClassForm input = (MyClassForm) form; // don't need this
input.setField1(“Hello”); // change to setMessage(“Hello”);
return mapping.findForward(“success”); // change to return Action.SUCCESS;
.jsp
Actions to be performed in this JSP are:
Replace <%# taglib %> directive
Use new set of tags defined by the struts-tags.tld
<%# taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Hello!</title>
</head>
<s:form action="submit.action" method="post">
<body>
<s:textfield label="Name" name=" field1" />
<s:property value="field1"/>
<s:submit" />
</body>
</s:form>
</html>
Cheers.
I got this resolved by upgrading struts version to 2.5.18. It also worked fine when I downgraded the struts version to 2.5.13.
But it is not recommended to use struts version between 2.5.16 and 2.3.36 (inclusive), so I have upgraded it to 2.5.18

PrimeFaces: File Upload View Not Updating

I have setup a JSF project using spring security. I am trying to get the FileUpload PrimeFaces to show the selected file after the user finishes browsing to the file.
I am using:
http://www.primefaces.org/showcase/ui/file/upload/single.xhtml
The problem is that after selection of a file nothing is shown in the view and the upload button will not be highlighted. Any help?
I did try the basic file upload and it does update the file name in the view
For basic view
http://www.primefaces.org/showcase/ui/file/upload/basic.xhtml
Could it be FireFox version I use v31.0?
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:b="http://bootsfaces.net/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form enctype="multipart/form-data">
<p:growl id="messages" showDetail="true" />
<p:fileUpload value="#{fileUploadController.file}" mode="simple" skinSimple="true"/>
<p:commandButton value="Submit" ajax="false" actionListener="#{fileUploadController.upload}" disabled="false" />
</h:form>
<h:form enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}" mode="advanced" dragDropSupport="false"
update="messages" sizeLimit="100000" fileLimit="3" allowTypes="/(\.|\/)(txt|gif|jpe?g|png)$/" />
<p:growl id="messages" showDetail="true" />
</h:form>
</h:body>
</html>
I do have this as well in my web.xml:
<!-- PrimeFaces Client Side Validation -->
<context-param>
<param-name>primefaces.CLIENT_SIDE_VALIDATION</param-name>
<param-value>true</param-value>
</context-param>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
POM:
<!-- PrimeFaces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.2</version>
<scope>compile</scope>
</dependency>
I had a similar problem before.
When you define your file upload component, make sure the fileupload component is unique. Get the id from your javaBeans.
Regarding the file name, it is a CSS issue.
If you open your inspector and dig through layers and layers of <tb> tags, you should see the name of your file. Tweak with your CSS to make the name visible.

Struts2: can't call action before rendering index.jsp

I've searched for this all over SO, but didn't find a similar situation with the same symptoms. I'm using Sruts2 and trying to invoke an action before rendering the main page of my application (index.jsp). I truly believe that this action is not being called, because I have a System.out.println() (for debugging purposes) in the beginning of the execute() method of the action that is not being printed. Indeed index.jsp is being presented (because it is the default page), but the part that is related to the action is not being run. In conclusion, I think that the problem may reside in the struts.xml file. Below are both the struts.xml and the action file:
Struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- The core configuration file for the framework is the default (struts.xml) file
and should reside on the classpath of the webapp (generally /WEB-INF/classes). -->
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- devMode equals debug information and reload everything for every request -->
<constant name="struts.devMode" value="true" />
<constant name="struts.ui.theme" value="simple" />
<package name="faultinjector" extends="struts-default">
<default-action-ref name="loadexperiments" />
<action name="loadexperiments" class="faultinjector.action.LoadExperimentsAction" method="execute">
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
LoadExperimentsAction.java:
public class LoadExperimentsAction extends ActionSupport
{
private static final long serialVersionUID = 4L;
private ExperimentService service;
private List <Experiment> experiments;
#Override
public String execute()
{
System.out.println("Hello!");
return SUCCESS;
}
public ExperimentService getService()
{
return service;
}
public void setService(ExperimentService service)
{
this.service = service;
}
public List<Experiment> getExperiments()
{
return experiments;
}
public void setExperiments(List<Experiment> experiments)
{
this.experiments = experiments;
}
}
I finally managed to achieve what I was looking for, without the need of redirecting pages. Basically the solution is to keep my original configuration, but changing the JSP page name from "index.jsp" to another one (in my case, it is now called "user_main".jsp). This way, it oddly works, I guess it has some hidden default configuration parameter when using the default name "index.jsp". Content of my configuration files:
web.xml:
<web-app id="faultinjector" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
struts.xml:
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.ui.theme" value="simple" />
<package name="faultinjector" extends="struts-default">
<default-action-ref name="loadexperiments" />
<action name="loadexperiments" class="faultinjector.action.LoadExperimentsAction" method="execute">
<result name="success">/user_main.jsp</result>
</action>
</package>
</struts>

Jira gadget is not working

I am trying to develop a gadget that will ultimately incorporate ChartJS, but I am having issues with the default gadget, as it does not load.
The code I am putting into the attlassian-plugin.xml is the following:
<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
<plugin-info>
<description>${project.description}</description>
<version>${project.version}</version>
<vendor name="${project.organization.name}" url="${project.organization.url}" />
<param name="plugin-icon">images/pluginIcon.png</param>
<param name="plugin-logo">images/pluginLogo.png</param>
</plugin-info>
<!-- add our i18n resource -->
<resource type="i18n" name="i18n" location="report"/>
<!-- add our web resources -->
<web-resource key="report-resources" name="report Web Resources">
<dependency>com.atlassian.auiplugin:ajs</dependency>
<resource type="download" name="report.css" location="/css/report.css"/>
<resource type="download" name="report.js" location="/js/report.js"/>
<resource type="download" name="images/" location="/images"/>
<context>report</context>
</web-resource>
<!-- publish our component -->
<component key="myPluginComponent" class="com.wfs.report.MyPluginComponentImpl" public="true">
<interface>com.wfs.report.MyPluginComponent</interface>
</component>
<!-- import from the product container -->
<component-import key="applicationProperties" interface="com.atlassian.sal.api.ApplicationProperties" />
<webwork1 key="demoaction" name="JTricks Demo Action" class="java.lang.Object">
<actions>
<action name="com.wfs.report.DemoAction" alias="DemoAction">
<view name="input">/templates/input.vm</view>
<view name="success">/templates/joy.vm</view>
<view name="error">/templates/tears.vm</view>
</action>
</actions>
</webwork1>
<atlassian-plugin name="Hello World" key="example.plugin.helloworld" plugins-version="2">
<plugin-info>
<description>A basic gadget module</description>
<vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/>
<version>1.0</version>
</plugin-info>
<gadget key="unique-gadget-key" location="gadget.xml"/>
</atlassian-plugin>
</atlassian-plugin>
and my gadget.xml which i put in the resources directory is:
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="JIRA Issues" author_email="adent#example.com" directory_title="JIRA Issues"
screenshot="images/screenshot.png"
thumbnail="images/thumbnail.png">
<Optional feature="dynamic-height" />
</ModulePrefs>
<Content type="html">
<![CDATA[
Hello, world!
]]>
</Content>
</Module>
</xml>
which I copied from https://developer.atlassian.com/display/GADGETS/Creating+your+Gadget+XML+Specification
yet I still get
It looks like you have one plugin descriptor nested inside another plugin descriptor. (I'm surprised that it actually passed validation!)
Change this:
<atlassian-plugin name="Hello World" key="example.plugin.helloworld" plugins-version="2">
<plugin-info>
<description>A basic gadget module</description>
<vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/>
<version>1.0</version>
</plugin-info>
<gadget key="unique-gadget-key" location="gadget.xml"/>
</atlassian-plugin>
to just this:
<gadget key="unique-gadget-key" location="gadget.xml"/>

problems with struts 2 developing login [duplicate]

This question already has answers here:
"The Struts dispatcher cannot be found" error while deploying application on WebLogic 12.1.3
(2 answers)
Closed 6 years ago.
I have several problems and I would if someone can help me to solve this with Struts 2. This is the problem I have. When I run my simple Login Application I have this mistake:
org.apache.jasper.JasperException: The Struts dispatcher cannot be found.
This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
The log is this one:
Advertencia: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60)
at org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44)
at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48)
at org.apache.jsp.Login_jsp._jspx_meth_s_form_0(Login_jsp.java:99)
at org.apache.jsp.Login_jsp._jspService(Login_jsp.java:72)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
The file tree is this one:
src(es.uniway.action.login as a package and inside this class:
LoginAction.java:
package com.uniway.action.login;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport{
#Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return SUCCESS;
}
}
As well inside of the src I have the struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.devMode" value="false" />
<package name="default" namespace="/" extends="struts-default">
<action name="Login" class="com.uniway.action.LoginAction">
<result name="input">/Login.jsp</result>
<result name="success" type="redirectAction">/index.jsp</result>
</action>
</package>
<!-- Add packages here -->
</struts>
Then at web-info folder I have the web.xml which I have this thing:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>cloud46</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>Login.jsp</welcome-file>
</welcome-file-list>
</web-app>
And after that at WebContent I have index.jsp and Login.jsp which I have this code:
<%# page contentType="text/html; charset=UTF-8" %>
<%# taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Sign On</title>
</head>
<body>
<s:form action="Login.action">
<s:textfield key="username"/>
<s:password key="password" />
<s:submit method="execute"/>
</s:form>
</body>
</html>
And the libraries at the lib folder inside of the WEB-INF are : asm-3.3.jar, asm-commons-3.3.jar, asm-tree-3.3.jar, commons-fileupload-1.2.2.jar, commons-io-2.0.1.jar, commons-lang3-3.1.jar, freemarker-2.3.19.jar, javassist-3.11.0.GA.jar, ognl-3.0.5.jar
, struts2-core-2.3.3.jar, xwork-core-2.3.3.jar . Please, what I'm doing wrong?
Do this
Change
<action name="Login" class="com.uniway.action.LoginAction">
<result name="input">/Login.jsp</result>
<result name="success" type="redirectAction">/index.jsp</result>
</action>
To
<action name="Login" class="com.uniway.action.LoginAction">
<result name="input">/Login.jsp</result>
<result name="success">/Login.jsp</result>
</action>
Change this
<s:form action="Login.action">
To
<s:form namespace="/" action="Login">
Next
Change
<s:submit method="execute"/>
To
<s:submit value="Login"/>
I had this problem with my 404.jsp page and this was my solution:
We should not use <s: tags in 404.jsp!!!
I don't know why, but this solved my problem!

Resources