Struts2的基本(手工)配制://上午2009-07-08
基本的登录:
login.jsp
<body>
<form action ="login.action" method = "post">
username:<input type = "text" name ="username"><br>
password:<input type = "password" name = "password"><br>
<input type="submit" value="submit">
</form>
</body>
注:在不用 tomcat不用发步工程时,想运行需要把项目存放的物理地址加到,加到tomcat下的conf/server.xml里
<Context path="/struts2" docBasc="D:/struts2/struts2/WebRoot" reloadable="true">
Struts2所依赖的jar包:
commons-loggin-1.0.4.jar
freemarker-2.3.8.jar
ognl-2.6.11.jar
struts2-core-2.0.11.jar
xwork-2.0.4.jar
web.xml
<web-app>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filger-name.
<url-pattern>/*</url-pattern>
<filter-mapping>
</web-app>
</web-app>
在src目录下创建struts.xml文件
struts.xml
//第一行的版本号:在struts2/的app下
<?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>
<package name="struts2" extends ="struts-default">
<action name="login" class = "com.test.action.LoginAction>
<result name="success" >/result.jsp</result>
</action>
</package>
</struts>
在src目录下建立com.test.action包
LoginAction.java
package com.test.action;
public class LoginAction{
private String username;
private String password;
public String getUsername(){
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPasswrod(){
return password;
}
public void setPassword(String password{
this.password= password;
}
public String exexute() throw Exception {
retrun "success";
}
}
result.jsp
<body>
username:${requestScope.username}<br>
password:${requestScope.password}<br>
</body>
-----------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------
Struts2的基本(手工)配制://下午2009-07-08
login2.jsp
<% page language="java" contentType="text/html; charset = ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri ="/struts-tags"%>
<html>
<head>
<title>Insert title here
</title>
</head>
<body>
<s:form action="login">
<s:textfield name="username" label="username"></s:textfield>
<s:password naem="passwrod" label = "password"></s:password>
<s:submit label="submit"></s:submit>
</s:form>
</body>
</html>
LoginAction.java
package com.test.action;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport{
private String username;
private String password;
public String getUsername(){
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPasswrod(){
return password;
}
public void setPassword(String password{
this.password= password;
}
public String exexute() throw Exception {
retrun "success";
}
public void validate(){
if(null=this.getUsername() ||"".equals(this.getUsername().trim())){
}
if(null=this.getPasswrod() ||"".equals(this.getPasswrod().trim())){
}
}
}