正在学习struts,请大家帮帮忙(100分)

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=&quot;GBK&quot;
contentType=&quot;text/html;
charset=gb2312&quot;
%>
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=gb2312&quot;/>
<title></title>
</head>
<body>
<form name=&quot;form1&quot;
method=&quot;post&quot;
action=&quot;/login.do&quot;>
<table width=&quot;300&quot;
border=&quot;0&quot;
cellspacing=&quot;0&quot;
cellpadding=&quot;0&quot;>
<tr align=&quot;center&quot;>
<td colspan=&quot;2&quot;>用户登录信息</td>
</tr>
<tr>
<td>用户名</td>
<td>
<input name=&quot;username&quot;
type=&quot;text&quot;
id=&quot;username&quot;
size=&quot;12&quot;>
user
</td>
</tr>
<tr>
<td>用户密码</td>
<td>
<input name=&quot;password&quot;
type=&quot;text&quot;
id=&quot;password&quot;
size=&quot;12&quot;>
123456
</td>
</tr>
<tr align=&quot;center&quot;>
<td colspan=&quot;2&quot;><input type=&quot;submit&quot;
name=&quot;Submit&quot;
value=&quot;提交&quot;></td>
</tr>
</table>
</form>
</body>
</html>
welcom.jsp
=================
<%@page pageEncoding=&quot;GBK&quot;
contentType=&quot;text/html;
charset=GBK&quot;
%>
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=GBK&quot;/>
<title></title>
</head>
<body>
<%
String type = request.getParameter(&quot;type&quot;);
if(type!=null&&type.equals(&quot;true&quot;)){
out.print(&quot;欢迎您的光临!&quot;);

}
else
{
out.print(&quot;对不起,你输入的用户名或者密码错误!&quot;);
}
%>
</body>
</html>

LoginForm.java
=================
package com.is.form;
import org.apache.struts.action.ActionForm;
public class LoginForm extends ActionForm {
private String username = &quot;&quot;;
private String password = &quot;&quot;;
/**
* @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(&quot;GB2312&quot;)))
{
response.setContentType
(&quot;text/html;
charset=GB2312&quot;);

} else
{
response.setContentType
(&quot;text/html;
charset=GBK&quot;);

}
try {
if (form instanceof LoginForm)
{
LoginForm theForm = (LoginForm) form;

if(theForm.getUsername().equals(&quot;user&quot;) &&
theForm.getPassword().equals(&quot;123456&quot;))
{
System.out.println(&quot;沙皮&quot;);
return new ActionForward(&quot;/loginok?type=true&quot;);

}

else
{
return new ActionForward(&quot;/loginerr?type=false&quot;);

}
}
} 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=&quot;1.0&quot;?>
<!DOCTYPE struts-config PUBLIC &quot;-//Apache Software Foundation//DTD Struts Configuration 1.1//EN&quot;
&quot;http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd&quot;>
<struts-config>
<data-sources>
</data-sources>
<form-beans>
<form-bean name=&quot;LoginForm&quot;
type=&quot;com.is.form.LoginForm&quot;>
<form-property name=&quot;username&quot;
type=&quot;java.lang.String&quot;></form-property>
<form-property name=&quot;password&quot;
type=&quot;java.lang.String&quot;></form-property></form-bean>
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards>
</global-forwards>
<action-mappings>
<action path=&quot;/login&quot;
name=&quot;LoginForm&quot;
type=&quot;com.is.form.LoginAction&quot;
scope=&quot;request&quot;
validate=&quot;true&quot;>
<forward name=&quot;loginok&quot;
path=&quot;/welcom.jsp&quot;></forward>
<forward name=&quot;loginerr&quot;
path=&quot;/welcom.jsp&quot;></forward>
</action>
</action-mappings>
<controller/>
</struts-config>
请大家建立这个环境,运行。
请问为什么系统总是运行不正确,提示错误如下:
type Status report
message /login.do
description The requested resource (/login.do) is not available.
我哪里配置错了,郁闷好久了。本人喜欢大富翁论坛,因为他有问必答,比别的论坛好多了
,所以就在这里发帖了。谢谢大家。
 
有问必答是真的,
可惜我现在还不会。。
帮你提前啦:) 哈哈。。。
 
是不是没编译啊
 
程序太长了,的确让人眼花,你先说明你的程序是完成什么功能,做了些什么。从头到尾没有什么注释,这不是好习惯。
如果你对struts还不太了解,建议你买一本书看看,是Struts作者 James Holmes 写的,中文译本,名字叫“Struts程序员手册”,中国铁道出版社出版的。
 
哈,这个本来是个试验性的程序,所以就每添加什么注释。实际上程序很简单,只要了解在eclipse下开发struts的模式就可以了(java的程序就是这么麻烦,配置这个配置那个的).
系统中主要涉及六个文件:
index.jsp,
welcom.jsp
LoginForm.java
LoginAction.java
上面这几个可以直接复制就可以
web.xml
struts-config.xml
这两个配置文件,我主要列出了自己添加的部分,把这部分添加进去就可以了。
Struts我不是很懂,正在学习,但是简单的结构还是了解的,例子程序也可以在我的环境下运行起来。但是,按照书上的说法,我自己做了个测试,上面的这个,死活就是运行不正确,我检查了好久,也没找到错误的地方,希望了解Struts的人能够给我指点。先谢了!
 
还有,能够希望大富翁也能开辟java的论坛,当然现在就有了,可是我觉得比delphi的论坛冷清多了。我在网上看了好多java的论坛,有两个问题:一是速度太慢,二是冷清的要命,三是操作性极差,哈哈,是三个问题。希望常上大富翁的会使用java的程序员就不要跑到别的地方去了,在这里多发些问题,多解决些问题就够了。我替使用delphi,并同时学习java技术的程序员谢了。
 
大家帮帮我呀,谢谢啦
 
<form-bean name=&quot;LoginForm&quot;
type=&quot;com.is.form.LoginForm&quot;>
<form-property name=&quot;username&quot;
type=&quot;java.lang.String&quot;></form-property>
<form-property name=&quot;password&quot;
type=&quot;java.lang.String&quot;></form-property></form-bean>
是配置动态actionform,你的LoginForm不是从DynaActionForm继承的,应该
<form-bean name=&quot;LoginForm&quot;
type=&quot;com.is.form.LoginForm&quot;/>才对。
 
to:chen_liang
是配置动态actionform,你的LoginForm不是从DynaActionForm继承的,应该
<form-bean name=&quot;LoginForm&quot;
type=&quot;com.is.form.LoginForm&quot;/>才对。
不定义form bean的属性,username和password,那么页面中的数据怎么存贮到LoginForm中,并且数据能够正确对应到username和password上呢
 
你要使用struts自己的标签库,这样LoginForm就能自动给username,password 赋值,
应该这样设置表单:
<html:form action=&quot;/login.do&quot;
method=&quot;post&quot;>
<html:text property=&quot;username&quot;/><br>
<html:text property=&quot;password&quot;/><br>
<html:submit value=&quot;Submit&quot;
property=&quot;Submit&quot;/>
<html:reset value=&quot;Reset&quot;/>
</hteml:form>
你用html自己标签,还不如不用struts
 
明白,谢谢楼上,继续学习
 
问题已经解决,谢谢各位支持
 

Similar threads

I
回复
0
查看
555
import
I
I
回复
0
查看
2K
import
I
I
回复
0
查看
2K
import
I
I
回复
0
查看
3K
import
I
顶部