请各位抽空帮小弟看下,谢谢
这是我的web.xml文件
[code="xml"]
<?xml version="1.0" encoding="UTF-8"?>
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">
index.jsp
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
[/code]
这是struts.xml文件
[code="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">
<!--
<include file="example.xml"/>
<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<action name="index">
<result type="redirectAction">
<param name="actionName">HelloWorld</param>
<param name="namespace">/example</param>
</result>
</action>
</package>
-->
<!-- Add packages here -->
<constant name="struts.devMode" value="true" />
<constant name="struts.ui.theme" value="simple" />
<package name="login" namespace="/login" extends="struts-defualt">
<action name="login" class="com.mycompany.student.action.LoginAction">
<result name="success">/main.jsp</result>
<result name="input">/index.jsp</result>
</action>
</package>
[/code]
这是LoginAction.java
[code="java"]
package com.mycompany.student.action;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class LoginAction extends ActionSupport {
private String username;
private String password;
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public String execute() throws Exception {
return SUCCESS;
/*if(getUsername().trim().equals("jim") && getPassword().trim().equals("123")) {
return SUCCESS;
}
else {
return INPUT;
}*/
}
@Override
public void validate() {
if(getUsername() == null || getUsername().trim().equals("")) {
addFieldError("userName", "请输入用户名称");
}
if(getPassword() == null || getPassword().trim().equals("")) {
addFieldError("passWord", "请输入用户密码");
}
}
}
[/code]
这是index.jsp文件
[code="jsp"]
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
用户名:
密码:
[/code]