码迷,mamicode.com
首页 > 其他好文 > 详细

Struts2.5框架搭建

时间:2015-03-03 16:47:19      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

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.jar
		commons-io-2.2.jar
		commons-lang-2.4.jar
		commons-lang3-3.1.jar
		commons-logging-1.1.3.jar
		freemarker-2.3.19.jar
		javassist-3.11.0.GA.jar
		log4j-1.2.14.jar
		ognl-3.0.6.jar
		struts2-core-2.3.16.3.jar
		xwork-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>



Struts2.5框架搭建

标签:

原文地址:http://blog.csdn.net/u010081710/article/details/44038533

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!