struts2 的HelloWrold程序
来源:互联网 发布:公务员面试 知乎 编辑:程序博客网 时间:2024/06/06 05:30
第一个struct 2的程序,实现用户登录
创建一个HelloWrold的web项目
1.1.1 配置WEB-INF目录下web.xml文件
view plaincopy to clipboardprint?
- <?xml version="1.0" encoding="UTF-8"?>
- <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">
- <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>/*</url-pattern>
- </filter-mapping>
- </web-app>
1.1.2 在src目录下创建并配置struts.xml文件
view plaincopy to clipboardprint?
- <?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.enable.DynamicMethodInvocation" value="false" />
- <constant name="struts.devMode" value="false" />
- <include file="example.xml"/>
- <package name="default" namespace="/" extends="struts-default">
- <action name="login" class="com.Action.LoginAction">
- <result name="Success">/Success.jsp</result>
- <result name="Error">/Error.jsp</result>
- </action>
- </package>
- <!-- Add packages here -->
- </struts>
1.1.3 Action业务控制器
view plaincopy to clipboardprint?
- package com.Action;
- public class LoginAction {
- 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 execute(){
- if("".equals(this.getUsername())||"".equals(this.getPassword())){
- return "Error";
- }else{
- return "Success";
- }
- }
- }
1.1.4 视图资源
success.jsp用来显示用户登录信息
view plaincopy to clipboardprint?
- <%@ 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 'Success.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" mce_href="styles.css">
- -->
- </head>
- <body>
- <h1>登录成功</h1>
- 用户名为:<%=request.getParameter("username") %>
- 密码为:<%=request.getParameter("password") %>
- </body>
- </html>
Error.jsp错误提示页面
view plaincopy to clipboardprint?
- <%@ 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 'Error.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" mce_href="styles.css">
- -->
- </head>
- <body>
- <h1>用户名或密码为空</h1>
- </body>
- </html>
- struts2 的HelloWrold程序
- struts2 的HelloWrold程序
- servlet的HelloWrold程序
- C语言程序的基本结构--HelloWrold篇
- node.js的HelloWrold
- HelloWrold!
- Hellowrold
- 我的第二个HelloWrold.
- Spring-MVC-01-简单的HelloWrold篇
- 学习新的编程语言需要HelloWrold的原因
- 简单粗暴的SSM学习——HelloWrold
- java HelloWrold
- Struts2的HelloWorld程序
- Struts2的HelloWorld程序
- Struts2的HelloWorld程序
- struts2的入门程序
- struts2的入门程序
- struts2 的第一个程序hello struts2
- C#不同类型的成员变量(字段)的默认值
- 字符透明编程自总结
- C#构造函数-创建对象
- 安装程序制作系统NSIS(Nullsoft Scriptable Install System)
- 创建存储过程
- struts2 的HelloWrold程序
- 替换思想
- C#实例化类的详细介绍
- J2ME SMS PUSH 短消息推送
- C#中对象的声明和使用
- C#访问修饰符
- Python基础知识(一)
- 编程错误收集
- [Android] Joystick游戏手柄开发