java - Action Attributes not showing on jsp -


so i'm following basic tutorials try show attribute action-class through property-tag. unfortunately results in showing nothing @ all. can call actions via action-tag.

here files

web.xml

<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>struts blank</display-name>  <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>  <welcome-file-list>     <welcome-file>index.jsp</welcome-file> </welcome-file-list> 

struts.xml

<?xml version="1.0" encoding="utf-8" ?> <struts>     <constant name="struts.devmode" value="true" />      <package name="default" extends="struts-default">              <action name="somebasic" class="basic">                     <result>/pages/login.jsp</result>             </action>      </package> </struts> 

index.jsp

<%@ page language="java" contenttype="text/html; charset=iso-8859-1"   pageencoding="iso-8859-1"%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <%@ taglib prefix="s" uri="/struts-tags"  %>  <html> <head>  </head> <body> test page...  <p>   should show firstname , lastname:   <s:property value="firstname"/>   <s:property value="lastname"/> </p>  </body> </html> 

basic.java

import com.opensymphony.xwork2.actionsupport;  public class basic extends actionsupport{     private string firstname = "me";     private string lastname = "i";      public string getfirstname() {         return firstname;     }      public void setfirstname(string firstname) {         this.firstname = firstname;     }      public string getlastname() {         return lastname;     }      public void setlastname(string lastname) {         this.lastname = lastname;     }      public string execute() {         return success;     }  } 

as mentioned, if put action-tag in .jsp file, called action triggered (when setting breakpoint). i'm missing configuration-thing or something. somebdoy had issue too?

i' running webapp on tomcat server , i'm using intellij 14 ide.

edit: aleksandr m eureka moment. totally misunderstood action concept. assumption action attributes initialised when wanting access them. must executed before using them (via url or action-tag).

struts2 mvc framwork struts mapping takes action , based on action results show jsp page. add 1 action in struts action class , take jsp page.

eg--

public string execute(){ return "success"; } 

and mapping in struts.xml be...

<action name="default" method="execute" class="your class name">         <result name="success" >fully qualified jsp page url</result>     </action> 

to learn struts2 go javabrains , start watching tutorials.


Comments