Action Attributes not showing on jsp

时间:2015-05-08 10:02:20

标签: java jsp tomcat intellij-idea struts2

So I'm following some basic tutorials where I try to show an attribute from an Action-Class through the property-tag. Unfortunately this results in showing nothing at all. But I can call actions via the action-tag.

Here my files

web.xml

public function get_like_total($data,$upload){
        $success = $this->db->insert('tbl_like',$data);

        //Query the total likes
        if($success){
            $this->db->select()->from('tbl_like');
            $this->db->where('uploadID',$upload);
            $this->db->where('like !=',2);
            $query = $this->db->get();

            return $query->num_rows();
        }

        return 0;       
    }

struts.xml

#include <iostream>

struct S {
    template <typename T>
    static T sum(T t){
        return t;
    }

    template <typename S, typename T>
    static auto sum(S s, T t) -> decltype(s + t) {
        return s + t;
    }

    template <typename S, typename T, typename ...U>
    static auto sum(S s, T t, U... u) -> decltype(s + t) {
        return s + sum(t, u...);
    }
};

int main() {
    std::cout << S::sum(1, 1.5, 2) << '\n';
}

index.jsp

<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>

basic.java

<?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>

As already mentioned, if I put an action-tag in the .jsp file, the called action would be triggered (when setting breakpoint). So probably I'm missing some configuration-thing or something. Does somebdoy had this issue too?

I' running my webapp on a Tomcat server and I'm using Intellij 14 as IDE.

Edit: Thanks to Aleksandr M for the eureka moment. I totally misunderstood the action concept. My assumption was that action attributes were already initialised when wanting to access them. But they must be executed before using them (via URL or action-tag).

1 个答案:

答案 0 :(得分:0)

Struts2是一个MVC框架,其中struts映射将您带到操作,并根据它显示Jsp页面的操作结果。 在Struts动作类中添加一个动作,它将带你进入你的jsp页面。

例如 -

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

并且struts.xml中的映射也将是......

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

正确学习struts2到javabrains并开始观看教程。