Hereunder is a Sample for reference only, If you are Junior, you could follow this mentioned step by step to create your own Project In Struts2. Sincerely hope you find it favorable.Thanks.
1.Import Jar Package;
struts2-core-2.x.x.jar
xwork-2.x.x.jar
ognl-2.6.x.jar
freemarker-2.3.x.jar
commons-logging-1.1.x.jar
2.Modify(Reset)configuration in Web.xml, and then Add Filter like that:
<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>
3.Create new struts.xml under src as:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration
2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
</struts>
4.Create Now Class 'LoginAction' and extends to Class 'ActionSupport'
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
}
5.Create New Jsp File which is refered to 'LoginAction'
6. Create Action Controler which should be related to Attributes Action in Jsp. And create get and set method to get and set Values.
String username;
String pwd;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
7.Default Method"execute" to realize the function, If success,return success,else return input.
public String execute(){
System.out.println("执行默认的execute方法!");
System.out.println("用户名:"+this.username);
System.out.println("密码:"+this.pwd);
return "success";
}
8 implenments Struts.xml and goto please be noted that when implement struts.xml, there are one file that "struts-
default.xml" must in, As for the package,extends struts-default (extends=“struts-default”)
<include file="struts-default.xml" />
<!-- extends表示要加载struts2框架默认的package -->
<package name="struts2" extends="struts-default">
<action name="loginAction" class="com.dgy.action.LoginAction">
<result name="success">Hello.jsp</result>
</action>
</package>
PS: This is original
分享到:
相关推荐
标题中的"Simple program demonstrating how to create a stop watch using the Timer control"揭示了这是一个关于使用Timer控件创建简单计时器程序的示例。这个程序可能是用Visual Basic (VB)编写的,因为文件名中...
How to Create a Database in Python using SQL Lite 3 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
this book tell you How to Create a Simple Web Dynpro Application for java,not for ABAP
This program shows you how to create a sample project that adds print preview capabilities to your Visual Basic program by using a generic object and the Printer object.
NULL 博文链接:https://blackbaby.iteye.com/blog/810567
VCL Layout Control - How to Create and Customize a Simple Layout [720p]
启示录 第二版 Marty Cagan(压缩卷第一部分,共三部分)
「安全研究」How to create a successful open source project - APT 区块链 安全研究 身份管理 NGFW 企业安全
How to create a donut chart like this in chart.js
How to Create a Database in Python using SQL Lite 3 英文mobi 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
How to Create a Database in Python using SQL Lite 3 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
How to Create a Database in Python using SQL Lite 3 英文无水印转化版pdf pdf所有页面使用FoxitReader、PDF-XChangeViewer、SumatraPDF和Firefox测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或...
启示录 第二版 Marty Cagan (压缩卷第二部分,共三部分) INSPIRED_ How to Create Tech Products Customers Love, 2nd Edition part2.rar
An example of how to create a coolbar such as the one in Internet Explorer without using a 3rd party control.
Sample01: How to create a simple 2D image and show it using OpenCV Window. Sample02: How to load and display images. Sample03: How to create a gray-scale image. Sample04: How to apply different ...
Charts I- How to create a chart(2).xlt
Charts I- How to create a chart.xlt
Sample01: How to create a simple 2D image and show it using OpenCV Window. Sample02: How to load and display images. Sample03: How to create a gray-scale image. Sample04: How to apply different ...
How to Create a Healthy Plate - English.srt