Struts2.5框架搭建

来源:互联网 发布:大数据可视化方法 编辑:程序博客网 时间:2024/05/22 16:58

struts2.5用到的基础开发包

Action类

package com.htf.action;import javax.servlet.http.HttpServletRequest;import org.apache.struts2.ServletActionContext;public class HelloWorld {/** * Struts2.5用到的基础开发包 * commons-fileupload-1.3.1.jarcommons-io-2.2.jarcommons-lang-2.4.jarcommons-lang3-3.1.jarcommons-logging-1.1.3.jarfreemarker-2.3.19.jarjavassist-3.11.0.GA.jarlog4j-1.2.14.jarognl-3.0.6.jarstruts2-core-2.3.16.3.jarxwork-core-2.3.16.3.jar */private String username = "";private String password = "";public String execute() {System.out.println("欢迎使用Struts2.....");HttpServletRequest request = ServletActionContext.getRequest();String Parameterusername=request.getParameter("username");String Attributeusername=(String) request.getAttribute("username");return "success";}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;}}
struts.xml配置文件

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"    "http://struts.apache.org/dtds/struts-2.3.dtd"><struts><package name="demo1" extends="struts-default"><action name="HelloWorld" class="com.htf.action.HelloWorld"><result name="success" >WEB-INF/jsp/helloworld_success.jsp</result><result name="fail">index.jsp</result></action></package></struts>    

用户登录页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">        <title>My JSP 'index.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">-->  </head>    <body>   <form action="HelloWorld.action" method="post">   用户名:  <input type="text" name="username" id="username" value=""/> <br>           密码: <input  type="text" name="password" id="password"  value=""/><br>           <input type="submit" value="登录">   </form>  </body></html>



0 1