zoukankan      html  css  js  c++  java
  • Struts2基础

    hello world 实例

    jsp页面:

    <%@ page contentType="text/html; charset=UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags"%>
    <html>
    <head></head>
    <body>
    	<h1>Struts 2 Hello World Example</h1>
    
    	<s:form action="Welcome">
    		<s:textfield name="username" label="Username" />
    		<s:password name="password" label="Password" />
    		<s:submit />
    	</s:form>
    
    </body>
    </html>



    action类:

    public class WelcomeUserAction {
    	
    	private String username;
    
    	public String getUsername() {
    		return username;
    	}
    
    	public void setUsername(String username) {
    		this.username = username;
    	}
    
    	// all struts logic here
    	public String execute() {
    
    		return "SUCCESS";
    
    	}
    }


    Struts.xml
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
    <struts>
    	<package name="user" namespace="/User" extends="struts-default">
    		<action name="Login">
    			<result>/login.jsp</result>
    		</action>
    		<action name="Welcome" class="com.yiibai.user.action.WelcomeUserAction">
    			<result name="SUCCESS">/welcome_user.jsp</result>
    		</action>
    	</package>
    </struts> 

     web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" 
    	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_3_0.xsd">
      <display-name></display-name>	
      <welcome-file-list>
        <welcome-file>index.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>*.action</url-pattern>
      </filter-mapping></web-app>
  • 相关阅读:
    Navicat Premium 15 永久激活版安装教程
    win10安装redis
    Linux下安装Go环境
    IoT platforms that deserves to be noticed
    TortoiseGit配置
    impot和require区别
    websocket搭建简单的H264实时视频流播放
    应用索引技术优化SQL 语句(Part 3)
    应用索引技术优化SQL 语句(Part 2)
    应用索引技术优化SQL 语句(Part 1)
  • 原文地址:https://www.cnblogs.com/yufeng1102/p/7638119.html
Copyright © 2011-2022 走看看