1

我创建了以下代码。但是在 apache tomcatv6.0 服务器中运行时,第二页即 Welcome.jsp 没有加载,而第一页,即 Login.jsp 已成功加载。有人能说编码有什么问题吗?我在 Java Resources 文件夹内的 src 文件夹中创建了 struts.xml。我正在使用 eclipse IDE。

StrutsDemo.java

package com.vishnu.struts;

import com.opensymphony.xwork2.ActionSupport;

public class StrutsDemo extends ActionSupport{
    String username;
    String password;
    String returnString=null;

    public String execute()
    {
        if(getUsername().equals("abc")&&getPassword().equals("abc123"))
        {

            returnString=SUCCESS;

        }
        else {
            returnString=ERROR;
        }
        return returnString;


    }

    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;
}

}  

登录.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Still TRY TRY...</title>
</head>
<body>

<s:textfield name="username"/>
<s:password name="password" value="Password"/>
<s:submit method="execute" label="Click" action="doLogin"/>


</body>
</html>

欢迎.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Thank God...</title>
</head>
<body>
<h1>Gud to see you!!!</h1>

</body>
</html>

struts.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">
<struts>

    <package name="default" namespace="/" extends="struts-default">


        <action name="doLogin" class="com.vishnu.struts.StrutsDemo" method="execute">

            <result name="success">/Welcome.jsp</result>
            <result name="error">/Login.jsp</result>
        </action>
        </package>
</struts>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>STRUTS INTRO-VISHNU</display-name>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


  <welcome-file-list>
<welcome-file>Login.jsp</welcome-file>

4

3 回答 3

1

尝试这个。你没有表格那么你的字段是如何发布的..

   <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Still TRY TRY...</title>
</head>
<body>
<s:form action="doLogin">
  <s:textfield name="username"/>
  <s:password name="password" value="Password"/>
  <s:submit label="Click"/>
</s:form>

</body>
</html>
于 2013-11-12T11:36:23.877 回答
0

尝试在 IDE 中清理项目,服务器也再次运行。五月有效。。

于 2013-11-12T11:05:16.097 回答
0

在您的 Login.jsp 中使用以下代码。

<form action="doLogin" method="POST">
<!--
Put all the content of Web Page here.,.
-->
</from>
于 2014-06-26T06:01:26.053 回答