L
lmax
Unregistered / Unconfirmed
GUEST, unregistred user!
开发环境:eclipse3.2+struts-1.2.9-bin.zip+tomcat5.0.28
两个jsp页面:index.jsp, welcom.jsp
一个formbean:LoginForm.java
一个formaction:LoginAction.java
配置文件:web.xml,struts-config.xml
内容分别如下:
index.jsp
=============
<%@page pageEncoding="GBK"
contentType="text/html;
charset=gb2312"
%>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html;
charset=gb2312"/>
<title></title>
</head>
<body>
<form name="form1"
method="post"
action="/login.do">
<table width="300"
border="0"
cellspacing="0"
cellpadding="0">
<tr align="center">
<td colspan="2">用户登录信息</td>
</tr>
<tr>
<td>用户名</td>
<td>
<input name="username"
type="text"
id="username"
size="12">
user
</td>
</tr>
<tr>
<td>用户密码</td>
<td>
<input name="password"
type="text"
id="password"
size="12">
123456
</td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit"
name="Submit"
value="提交"></td>
</tr>
</table>
</form>
</body>
</html>
welcom.jsp
=================
<%@page pageEncoding="GBK"
contentType="text/html;
charset=GBK"
%>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html;
charset=GBK"/>
<title></title>
</head>
<body>
<%
String type = request.getParameter("type"
if(type!=null&&type.equals("true"){
out.print("欢迎您的光临!"
}
else
{
out.print("对不起,你输入的用户名或者密码错误!"
}
%>
</body>
</html>
LoginForm.java
=================
package com.is.form;
import org.apache.struts.action.ActionForm;
public class LoginForm extends ActionForm {
private String username = "";
private String password = "";
/**
* @return Returns the password.
*/
public String getPassword()
{
return password;
}
/**
* @param password The password to set.
*/
public void setPassword(String password)
{
this.password = password;
}
/**
* @return Returns the username.
*/
public String getUsername()
{
return username;
}
/**
* @param username The username to set.
*/
public void setUsername(String username)
{
this.username = username;
}
}
LoginAction.java
===========================
package com.is.form;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
String encoding = request.getCharacterEncoding();
if ((encoding != null) &&
(encoding.equalsIgnoreCase("GB2312"))
{
response.setContentType
("text/html;
charset=GB2312"
} else
{
response.setContentType
("text/html;
charset=GBK"
}
try {
if (form instanceof LoginForm)
{
LoginForm theForm = (LoginForm) form;
if(theForm.getUsername().equals("user" &&
theForm.getPassword().equals("123456")
{
System.out.println("沙皮"
return new ActionForward("/loginok?type=true"
}
else
{
return new ActionForward("/loginerr?type=false"
}
}
} catch (Exception e)
{
}
// this shouldn't happen in this example
return null;
}
}
web.xml
==================================
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
struts-config.xml
=============================
<?xml version="1.0"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<data-sources>
</data-sources>
<form-beans>
<form-bean name="LoginForm"
type="com.is.form.LoginForm">
<form-property name="username"
type="java.lang.String"></form-property>
<form-property name="password"
type="java.lang.String"></form-property></form-bean>
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards>
</global-forwards>
<action-mappings>
<action path="/login"
name="LoginForm"
type="com.is.form.LoginAction"
scope="request"
validate="true">
<forward name="loginok"
path="/welcom.jsp"></forward>
<forward name="loginerr"
path="/welcom.jsp"></forward>
</action>
</action-mappings>
<controller/>
</struts-config>
请大家建立这个环境,运行。
请问为什么系统总是运行不正确,提示错误如下:
type Status report
message /login.do
description The requested resource (/login.do) is not available.
我哪里配置错了,郁闷好久了。本人喜欢大富翁论坛,因为他有问必答,比别的论坛好多了
,所以就在这里发帖了。谢谢大家。
两个jsp页面:index.jsp, welcom.jsp
一个formbean:LoginForm.java
一个formaction:LoginAction.java
配置文件:web.xml,struts-config.xml
内容分别如下:
index.jsp
=============
<%@page pageEncoding="GBK"
contentType="text/html;
charset=gb2312"
%>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html;
charset=gb2312"/>
<title></title>
</head>
<body>
<form name="form1"
method="post"
action="/login.do">
<table width="300"
border="0"
cellspacing="0"
cellpadding="0">
<tr align="center">
<td colspan="2">用户登录信息</td>
</tr>
<tr>
<td>用户名</td>
<td>
<input name="username"
type="text"
id="username"
size="12">
user
</td>
</tr>
<tr>
<td>用户密码</td>
<td>
<input name="password"
type="text"
id="password"
size="12">
123456
</td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit"
name="Submit"
value="提交"></td>
</tr>
</table>
</form>
</body>
</html>
welcom.jsp
=================
<%@page pageEncoding="GBK"
contentType="text/html;
charset=GBK"
%>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html;
charset=GBK"/>
<title></title>
</head>
<body>
<%
String type = request.getParameter("type"
if(type!=null&&type.equals("true"){
out.print("欢迎您的光临!"
}
else
{
out.print("对不起,你输入的用户名或者密码错误!"
}
%>
</body>
</html>
LoginForm.java
=================
package com.is.form;
import org.apache.struts.action.ActionForm;
public class LoginForm extends ActionForm {
private String username = "";
private String password = "";
/**
* @return Returns the password.
*/
public String getPassword()
{
return password;
}
/**
* @param password The password to set.
*/
public void setPassword(String password)
{
this.password = password;
}
/**
* @return Returns the username.
*/
public String getUsername()
{
return username;
}
/**
* @param username The username to set.
*/
public void setUsername(String username)
{
this.username = username;
}
}
LoginAction.java
===========================
package com.is.form;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
String encoding = request.getCharacterEncoding();
if ((encoding != null) &&
(encoding.equalsIgnoreCase("GB2312"))
{
response.setContentType
("text/html;
charset=GB2312"
} else
{
response.setContentType
("text/html;
charset=GBK"
}
try {
if (form instanceof LoginForm)
{
LoginForm theForm = (LoginForm) form;
if(theForm.getUsername().equals("user" &&
theForm.getPassword().equals("123456")
{
System.out.println("沙皮"
return new ActionForward("/loginok?type=true"
}
else
{
return new ActionForward("/loginerr?type=false"
}
}
} catch (Exception e)
{
}
// this shouldn't happen in this example
return null;
}
}
web.xml
==================================
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
struts-config.xml
=============================
<?xml version="1.0"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<data-sources>
</data-sources>
<form-beans>
<form-bean name="LoginForm"
type="com.is.form.LoginForm">
<form-property name="username"
type="java.lang.String"></form-property>
<form-property name="password"
type="java.lang.String"></form-property></form-bean>
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards>
</global-forwards>
<action-mappings>
<action path="/login"
name="LoginForm"
type="com.is.form.LoginAction"
scope="request"
validate="true">
<forward name="loginok"
path="/welcom.jsp"></forward>
<forward name="loginerr"
path="/welcom.jsp"></forward>
</action>
</action-mappings>
<controller/>
</struts-config>
请大家建立这个环境,运行。
请问为什么系统总是运行不正确,提示错误如下:
type Status report
message /login.do
description The requested resource (/login.do) is not available.
我哪里配置错了,郁闷好久了。本人喜欢大富翁论坛,因为他有问必答,比别的论坛好多了
,所以就在这里发帖了。谢谢大家。