javaweb struts2 登陆小程序

首先配置环境,主要做的就是1,tomcat能起来。2,将struts2的包复制到web-inf/lib目录下(这个在myecplise上没法导入的,可以自己手动在文件夹中复制,但是我一开始写的时候直接导的包并没放到lib位置,一样可以执行)
程序:
loginaction.java

package com.helloweenvsfei.struts2.action;

import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {

    private String account;
    private String password;
    public String execute(){
        if("helloween".equalsIgnoreCase(account)&&"1234".equals(password)){
            return SUCCESS;
        }
        return LOGIN;

    }
    public String getAccount(){
        return account;

    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public void setAccount(String account) {
        this.account = account;
    }

}

login.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="struts" %>



<html>
  <head>

    <title>My JSP 'login.jsp' starting pagetitle>
      <struts:head theme="ajax" />

  head>

  <body>
    <struts:form action="loginPerson">
    <struts:label value="登录系统">struts:label>
    <struts:textfield  name="account" label="账号"/>
      <struts:password name="password" label="密码"/>
      <struts:submit value="登陆">struts:submit>
      struts:form>
  body>
html>

success.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="struts" %>


<html>
  <head>


    <title>My JSP 'success.jsp' starting pagetitle>

     <struts:head theme="ajax" />

  head>

  <body>
    登陆成功,欢迎你, <struts:property value="account"/>
  body>
html>

struts.xml


    
<struts>
<package name="main" extends="struts-default">
 
<global-results>
<result name="login">/login.jspresult>
global-results>
 
<action name="loginPerson"
        class="com.helloweenvsfei.struts2.action.LoginAction">
 
       <result name="success">/success.jspresult>       
action>
package>

struts>

web.xml


<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <filter>
  
  <filter-name>strutsfilter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcherfilter-class>
  <init-param>
  <param-name>struts.action.extensionparam-name>
  <param-value>actionparam-value>
  init-param>
  filter>
  
  <filter-mapping>
  <filter-name>strutsfilter-name>
  
  <url-pattern>/*url-pattern>
  filter-mapping>
  <welcome-file-list>
    <welcome-file>index.jspwelcome-file>
  welcome-file-list>
web-app>

你可能感兴趣的:(javaweb,源码分享,struts2)