struts

Create multiple methods in one action class itself in Struts2?

北城以北 提交于 2019-12-01 14:17:15
Can I create two methods in the same Action Class? If so how can we specify it in the struts.xml file ? For example : I created a simple validation action class to validate the email address as well as password using two separate regular expression. I created two Methods in the Action class say: emailVerification() and passVerification() . I wrote all the necessary validation code inside, but now when they return SUCCESS they should result into the same success page result and for ERROR likewise.. Uchenna Nwanyanwu Yes you can create any number of methods in an Action Class. You can do

How to wtite pretty URL in Struts2.x?

◇◆丶佛笑我妖孽 提交于 2019-12-01 14:01:25
I want to rewrite my URL in Struts2. Please help me out to do this. How can i customize as i want, i don't want to show my parameter that i am passing and also show action with different name that i want I don't know how to do it. i have to use plugins for that or configure my code in struts.xml <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.action.extension" value="action" /> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts

Create multiple methods in one action class itself in Struts2?

若如初见. 提交于 2019-12-01 13:14:15
问题 Can I create two methods in the same Action Class? If so how can we specify it in the struts.xml file ? For example : I created a simple validation action class to validate the email address as well as password using two separate regular expression. I created two Methods in the Action class say: emailVerification() and passVerification() . I wrote all the necessary validation code inside, but now when they return SUCCESS they should result into the same success page result and for ERROR

SSH框架中不为人知的细节(一)

跟風遠走 提交于 2019-12-01 12:48:58
一、 ModelDriven的运行机制 大家都知道前台表单数据向后台传递的时候,调用的Action会实现ModelDriven接口。伪码如下: VO伪码: public class User { private String userName; private String password; //setter and getter //.... } Action伪码: public class UserAction implements ModelDriven { private User user = new User(); public String addUser() { //相应的业务逻辑 } @Override public Object getModel() { return user; } } JSP伪码: <form action="xxx/user-add.action" method="post"> username:<input type="text" name="username" /> password:<input type="text" name="password" /> <input type="submit" name="submit" value="添加" /> </form> 上面的代码相信大家非常熟悉

Struts2-Value Stack浅析

╄→尐↘猪︶ㄣ 提交于 2019-12-01 12:48:32
Value Stack的作用: 1. 可以作为一个数据中转站 2. 用于在前台 - 后台之间传递数据,最典型的做法就是 struts2 标签也 ognl 表达式的结合。我用得最多的就是数据回显。 Value Stack的生命周期: 在 struts-default.xml 文件中决定了在 web 容器启动时将会创建 OgnlValueStackFactory 对象,该对象实现了 ValueStackFactory 接口,负责 ValueStack 的创建工作。 ValueStack 的生命周期是随着 request 的创建而创建,随 request 的销毁而销毁。具体可见源代码: 在 PrepareOperations 类的 createActionContext 中有 至于清理工作, struts 统一放在了 PrepareOperations 类的 cleanupRequest 方法中。 Value Stack结构: 主要看 OgnlValueStack 类,此类实现了 ValueStack 接口。 在 OgnlValueStack 中有两个至关重要的东西, ,简称“对象栈 ” 和 “Map 栈 ” 。 CompoundRoot: CompoundRoot 继承了 ArrayList 类,即是一个 List 集合,详见源码 CompoundRoot 类。 Context: 而

How to open one jsp from another through struts

半世苍凉 提交于 2019-12-01 11:13:59
How to open One jsp from another through Struts ? For example, I have 2 JSPs, Page1.jsp & Page2.jsp. Page1.jsp does not contain any Form. Page2.jsp contains a Form . I need a link on Page1.jsp which when clicked takes me to Page2.jsp . What are the Actionmappings needed to be added to struts-config.xml ? Update: I tried adding these lines in Page1.jsp <html:link page="Page2.do">Page2</html:link> <a href="Page2.do">Page2</a> In struts-config.xml , the following Action-mapping <action path="/Page2" parameter="Page2.jsp" type="org.apache.struts.actions.ForwardAction"/> The "href" one works, while

Generate name and value attribute dynamically in Struts 2

試著忘記壹切 提交于 2019-12-01 10:41:45
I am migrating the code from Struts1 to Struts2 Struts1 code <input type="text" value="<c:out value="${serviceVO.notifList}"/>" name="ServicesNotifList-<c:out value="${serviceVO.globalId}"/>#<c:out value="${serviceVO.id}"/>" size="50" maxlength="1000"/> in Struts2 I tried but not working <c:set var="notifListTemp" value="ServicesNotifList-"></c:set> <c:set var="notifListTemp1" >${notifListTemp}${serviceVO.globalId}</c:set> <c:set var="notifListTemp2" value="#"></c:set> <c:set var="notifListTemp3" >${notifListTemp1}${notifListTemp2}${serviceVO.id}</c:set> <s:textfield theme="simple" value="$

How to open one jsp from another through struts

為{幸葍}努か 提交于 2019-12-01 09:18:08
问题 How to open One jsp from another through Struts ? For example, I have 2 JSPs, Page1.jsp & Page2.jsp. Page1.jsp does not contain any Form. Page2.jsp contains a Form . I need a link on Page1.jsp which when clicked takes me to Page2.jsp . What are the Actionmappings needed to be added to struts-config.xml ? Update: I tried adding these lines in Page1.jsp <html:link page="Page2.do">Page2</html:link> <a href="Page2.do">Page2</a> In struts-config.xml , the following Action-mapping <action path="

Struts2核心技术 (二)

寵の児 提交于 2019-12-01 09:13:48
struts2中的参数封装 静态参数封装 什么是静态参数? 静态参数就是硬编码的,不可随意改变。 例子 : 我们首先创建一个Action类,里面有两个参数,用来封装请求参数 public class User extends ActionSupport { private String username; //用户名 private int age; //年龄 public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String adduser(){ System.out.println(username+":"+age); return null; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 我们在struts.xml中配置静态参数 <package name="p1" extends="struts

Struts2 ActionContext and ValueStack?

自古美人都是妖i 提交于 2019-12-01 08:31:47
My questions are: In Struts2, does every action object have its own corresponding ActionContext and ValueStack? In other words, for every new request a new action object is created. Does this mean every time a new action object is created, a new ActionContext and ValueStack also get created? Consider this scenario: Action1------1st req------->view.jsp------2nd req--------->action2. So when a request comes for action1 a new object of action1 and corresponding ActionContext and ValueStack will get created. From view.jsp (upon clicking hyperlink) a new request goes for action2. Does this mean