亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

eclipse開發struts2程序

系統 1892 0
    
在eclipse下,用sturts2實現登錄功能

  

    
代碼結構如下:

  


eclipse開發struts2程序

web.xml代碼:
    
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
	id="WebApp_ID" version="3.0">
	<display-name>struts</display-name>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>

	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>

	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
</web-app>

  


struts.xml代碼:
    
<?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>
	<constant name="struts.devMode" value="true" />
	<package name="default" namespace="/" extends="struts-default">
		<action name="*Action" class="com.action.struts.LoginAction" method="{1}">
			<result name="success">/main.jsp</result>
			<result name="login">/login.jsp</result>
		</action>
	</package>
</struts>


  


LoginAction代碼:
    
package com.action.struts;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction  extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	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 login(){
    	System.out.println("username :"+username);
    	System.out.println("password :"+password);
    	System.out.println("login method invoke");
    	if("yangjianzhou".equals(username)&&"123456".equals(password)){
			Map session = ActionContext.getContext().getSession();
    		session.put("username", username);
    		return "success";
    	}
    	return "login";
	}
}


  


login.jsp代碼:
    
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!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>login</title>
</head>
<body>
	<div style="margin-top: 50px;" align="center">登錄界面</div>
	<form action="loginAction" method="post">
		<table align="center" style="margin-top: 20px;">
			<tr>
				<td>用戶名:</td>
				<td><input type="text" name="username"></td>
			</tr>
			<tr>
				<td>密 碼:</td>
				<td><input type="password" name="password"></td>
			</tr>
			<tr>
				<td></td>
				<td><input type="submit" value="提交"></td>
			</tr>
		</table>
	</form>
</body>
</html>

  


main.jsp代碼:
    
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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>main</title>
</head>
<body>
   <div style="margin-top: 50px;" align="center">
   Welcome to home page : <%=(String)session.getAttribute("username") %></div>
</body>
</html>

  


運行界面:

eclipse開發struts2程序


eclipse開發struts2程序

eclipse開發struts2程序


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲一区中文字幕在线 | 丁香色婷婷 | 久久综合九色综合97婷婷群聊 | 亚洲另类视频在线观看 | 永久黄网站色视频免费 | 亚洲一本通 | 青青青爽线在线视频观看 | 精品久久久久久综合日本 | 欧美精品福利视频 | 2022国内精品免费福利视频 | 奇米在线免费视频 | 亚洲成人视 | 国产午夜精品视频 | 欧美成年黄网站色高清视频 | 久久99视频精品 | 黄色网址中文字幕 | 免费一级毛片在线播放泰国 | 欧美一级高清在线观看 | xxxxyoujizz护士 | 中文字幕精品视频 | 麻豆射区 | 日本一区二区三区在线观看 | 国产精品亚洲精品不卡 | 久久精品无码一区二区三区 | 色黄网站成年女人色毛片 | 欧美成人免费视频a | 波多野结衣在线一区 | 超清波多野结衣精品一区 | 国产色综合天天综合网 | 四虎在线最新永久免费播放 | 免费看羞羞视频的网站 | 欧美另类videosbestv | 毛片毛片毛片毛片 | 中文字幕永久视频 | 色激情综合网 | 久在草影院 | 国产一区二区三区乱码网站 | 五月婷婷婷婷 | 天天插天天射天天干 | 免费一级毛片在级播放 | 久久一区二区三区免费播放 |