Struts 2 Tutorial cont. w/ Accessing Input Parameters

Data transfer between input URL request and Action class------>http get request

It could be available by mapping a private field in the action class to the execute() method body through the help of Struts interceptor. The URL input parameters will be stored to the related action class private field varible by the public setter function(used to do the value assignment from the URL parameters to Action class private field variables) of the action class . So basiclly the value stack helps the data transfer from bom both input from URLs and output to JSPs

Post requests to actions------>http post request

same handling way as the http get request.

The struts form using struts tags and the http default form.

 firstly to add struts taglib; <%@ taglib prefix="c" uri="/struts-tags" />

 Then using Struts form as below:

<s:form action="no .action needed">

<s:testfield (lable="enter the language your want") key="(the field variables to be populated)" /> 

<s:submit />

</s:form>

before i wind up, the <.action> extension does not need to be in place

 

Login Action and Best Practices

Login JSP page is created

<s:password label="password" key="password">

Loginaction class is created with getter and setter methods in place

New package with new namespace name<namespace="/"> and package name <package name= "login"> should be added to the structs xml file.

Not hard-code the return value instead of using the <private static String SUCCESS="success">

The Struts provides the both class to extend and the interface(Action which contains a  lot of static common Strings) to implements for the action class in order to decrease the redundent code reusage.

It is allowed to have multi xml files which could be included in the struts.xml file rather than the only main structs.xml to make it more organized;

So create a new xml file named login_struts.xml which only include the login package as a particular unit or business group;

In the main struts.xml file, it could add such line like, <include file="login.xml">

Use alias and dummy action class  --->this needs  to be double checked.......

<package name = "search" namespace="/" exttends="">

<action name="searchForm">

<result>/searchForm.jsp</resuot>

</action>

</package>

Action Wildcards

 

Single action name is mapped to multi actions;

STRUTS checks based a top-down order from within the strusts.xml when doing wildcards mapping

----For result wildcard match

<action name="search*">

<result>/search{1}.jsp</result>

</action>

----For class wildcard match

<action name="get*" class="com.infor.{1}Action">

<result>/search{1}.jsp</result>

</action>

 

The ActionSupport Class

Writing strust 2 action and attch the resource to the eclipse so you could see the source code:

POJO ;

Action interface ;

ActionSupport class ;

<result name="input">/login.jsp</result>

Public class LoginAction extend ActionSupport

{

 

}

What should be paid attention to is the <public validate()> method in the actionsupport class which will be executed before the running of execute() method;

public void validate()

{

if stringUtil.isEmpty(userId)

{

addFieldError("userid, ""User ID connot be blank")

}

if stringUtil.isEmpty(password)

{

addFieldError("userid", "password"connot be blank")

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要爬取 https://www.runoob.com/manual/pythontutorial/docs/html/ 中的一段文本,可以使用 Python 的 requests 库和 BeautifulSoup 库。 以下是一个示例代码,用于爬取 Python 教程中第一篇文章的第一段内容: ```python import requests from bs4 import BeautifulSoup url = 'https://www.runoob.com/manual/pythontutorial/docs/html/python-beginner.html' response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') content = soup.find('div', class_='article-intro').p.text.strip() print(content) ``` 首先,使用 requests 库获取 Python 教程的第一篇文章的页面内容,并将其存储在变量 response 中。 接着,使用 BeautifulSoup 库解析页面内容,并使用 `soup.find()` 方法找到页面中的 class 为 `article-intro` 的 div 元素,然后再从这个 div 元素中找到第一个 p 标签元素。 最后,使用 `text` 属性获取 p 标签元素的文本内容,并使用 `strip()` 方法去除文本内容前后的空格和换行符。 执行上述代码,输出第一篇文章的第一段内容: ``` Python 是一种解释型、面向对象、动态数据类型的高级程序设计语言。Python 由 Guido van Rossum 于 1989 年底发明,第一个公开发行版发行于 1991 年。Python 语法简洁而清晰,具有丰富和强大的类库。它常被称为胶水语言,能够把用其他语言制作的各种模块(尤其是 C/C++)很轻松地联结在一起。Python 适用于大多数平台,包括 Windows、Linux、Unix、Mac OS X 等,并且有许多第三方库可以帮助我们进行各种操作。 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值