<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
<form action="login.action" method="post">
username:<input type="text" name="username" /><p>
password:<input type="password" name="password" /><p>
<input type="submit" name="Submit" value="submit" />
</form>
</body>
</html>
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
username:${requestScope.username}<br>
password:${requestScope.password}
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
struts2.0</display-name>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2.0</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2.0</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
package com.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 getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute()throws Exception{
return "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="struts2.0" extends="struts-default">
<action name="login" class="com.action.loginAction">
<result name="success">/result.jsp</result>
</action>
</package>
</struts>
<s:form action="login">
<s:textfield name="username" label="username"></s:textfield>
<s:password name="password" label="password"></s:password>
<s:submit label="submit"></s:submit>
</s:form>
@Override
public void validate() {
if(null==this.getUsername()||"".equals(this.getUsername().trim())){
this.addFieldError("username", "username error");//Add error message
}
if(null==this.getPassword()||"".equals(this.getPassword().trim())){
this.addFieldError("password", "password error");//Add error message
}
}
<?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.0" extends="struts-default">
<action name="login" class="com.action.loginAction">
<!-- Add the page returned by the error -->
<result name="input">/login.jsp</result> <result name="success">/result.jsp</result>
</action>
</package>
</struts>
public String execute()throws Exception{
if("hello".equals(this.getUsername().trim())&&"world".equals(this.getPassword().trim())){
return "success";
}
else{
this.addFieldError("username", "username or password error");//Defined error message above username
return "failer";
}
}
<?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.0" extends="struts-default">
<action name="login" class="com.action.loginAction">
<result name="input">/login.jsp</result>
<result name="success">/result.jsp</result>
<!-- Increase the failer map -->
<result name="failer">/login.jsp</result>
</action>
</package>
</struts>
Struts2.0 action address conversion Configure Struts core filter Create struts.xml Write Action Struts process Struct constant configuration struts.xml modularization Struts Action class Action access...
Summary of the preliminary learning of Struts2.0 Struts2 is a Web application framework based on the MVC design pattern, which is essentially equivalent to a servlet. In the MVC design pattern, Struts...
mainly needs the following jar packages: struts2-core-2.1.6.jar xwork-2.1.2.jar ognl-2.6.11.jar freemarker-2.3.13.jar commons-logging.jar commons-fileupload.jar commons-io.jar log4j-1.2.15.jar Log4j.p...
Promotion: The Taobao shop opened by yourself, the main car accessories, accessories, you can go in and see, it is best to help the buddy to promote Store name:Xuanyuan car accessories &nb...
One: Review the processing flow of struts2.0...
[b]Struts2.0 direct data transfer: [/b][align=center][/align] 1. Pass data between action and action: In the first action, use the execute() method: //getUser() is the encapsulation of the parameter n...
Struts2 file upload defaults to the apache file upload package, the new processing upload Servlet is as follows: Create a new folder under WebRoot: upload, an upload folder in the server...
Java code Need to import the file,: Java code Java code...
2010.06.23——— spring+struts2.0 configuration web.xml applicationContext.xml spring configuration file Struts.xml struts2 configuration file Inject dao inside jdbcTemplage, service in...