呵呵~一鼓作氣!再弄點!HelloWorld不能一直下去吧!
HelloWorld裏的struts.xml很簡單。
- <package name="default" extends="struts-default">
- <action name="hello">
- <result >
- helloworld.jsp
- </result>
- </action>
- </package>
package com.hello.model;
import com.opensymphony.xwork2.ActionSupport;
public class UserLoginAction extends ActionSupport {
private String userName ;
private String password ;
public String getUserName() {
System.out.println("getUserName");
return userName;
}
public void setUserName(String userName) {
System.out.println("setUserName");
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String add() {
System.out.println(userName + " has been accepted!");
return ActionSupport.SUCCESS;
}
}
<?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="default" extends="struts-default">
<action name="login" class = "com.hello.model.UserLoginAction">
<result>
mainMenuContent.jsp
</result>
</action>
</package>
</struts>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="login?userName=zoe?password=56"">User Zoe Login!</a>
</body>
</html>
mainMenuContent.jsp<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Add operation successes!
</body>
</html>
<?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="default" extends="struts-default">
<action name="login" class = "com.hello.model.UserLoginAction" method="add" >
<result>
mainMenuContent.jsp
</result>
</action>
</package>
</struts>
zoe?password=56 has been accepted!