51,409
社区成员
发帖
与我相关
我的任务
分享package com.common.controller;
import com.common.entityOperation.*;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
public class LoginAction implements Action {
static{
System.out.println("进入action");
}
private String studentNo;
private String pwd;
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public String getTest() {
return studentNo;
}
public void setTest(String studentNo) {
this.studentNo = studentNo;
}
@InputConfig(methodName="login")
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return login(studentNo,pwd);//SUCCESS; //视图
}
public String login(String studentNo,String pwd){
if(studentNo.isEmpty() || pwd.isEmpty()){
return ERROR;
}
try {
if(new OperationTStudent().exist(studentNo, pwd)){
return SUCCESS;
}
} catch (Throwable e) {
e.printStackTrace();
}
return ERROR;
}
}
<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>helloHibernate</display-name>
<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>
<?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>
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
<package name="def" namespace="/" extends="struts-default">
<action name="loginAction" class="com.common.controller.LoginAction" method="login">
<result name="success" type="dispatcher">index.jsp</result>
<result name="error">error.jsp</result>
</action>
</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>登录页面</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>
<div align="center">
你输入的账号信息
<form action="LoginAction" method = "post">
账号: <input type="text" name="TStudent.studentNo" size="30">
密码: <input type="text" name="TStudent.pwd" size="30">
<input type="submit" value="登录">
</form>
</div>
</body>
</html>
