急!!!请高手看看Struts为什么报错!!!

Suspend 2005-03-01 04:29:41
我只想测试看Struts如何连数据库,所以程序很简单。请大家看看我的代码为什么报错!!

Login.jsp :

<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html>
<head>
<title>
indexjsp
</title>
</head>
<body>
<!--html:errors/><p-->
<!--logic:present name="hy" scope="request"-->
<!--/logic:present-->

<html:form action="LoginAction.do" method="post" focus="dbaName">
<br><br><br><br>
<p align="center">输入用户名:
<html:text property="dbaName" size="16" maxlength="16" />
<!--/html:text-->
<p align="center">请输入密码:
<html:password property="dbaPswd" size="16" maxlength="16" />
<!--/html:password-->
</html:form>
</body>
</html:html>



...全文
73 点赞 收藏 11
写回复
11 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
lovelanzhi716 2005-03-01
就按楼上的写就可以了
回复
Suspend 2005-03-01
这个数据库是没有密码的。那我的set-property property="password" 应该如何写?
我现在在Tomcat下都运行不起来啊!!
回复
jFresH_MaN 2005-03-01
而且你的<html;form>里面少一个提交按钮啊
回复
jFresH_MaN 2005-03-01
<set-property property="password" value=""/>
回复
Suspend 2005-03-01
Main.jsp没有东西。我只是测试数据库连接,不考虑业务逻辑,而且密码验证总是对的。这个SQL的驱动和URL我在JB的DataBase Pilot里测试过是,是正确的。可是报错:


信息: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true

2005-3-1 16:36:33 org.apache.struts.util.PropertyMessageResources <init>

信息: Initializing, config='org.apache.struts.action.ActionResources', returnNull=true

2005-3-1 16:36:33 org.apache.commons.digester.Digester error

严重: Parse Error at line 14 column -1: “value”的属性值为 #REQUIRED。

org.xml.sax.SAXParseException: “value”的属性值为 #REQUIRED。

at org.apache.crimson.parser.Parser2.error(Parser2.java:3160)

at org.apache.crimson.parser.Parser2.defaultAttributes(Parser2.java:1742)

at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1453)

at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)

at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)

at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)

at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)

at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)

at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)

at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:500)

at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)

at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)

at org.apache.commons.digester.Digester.parse(Digester.java:1543)

at org.apache.struts.action.ActionServlet.initModuleConfig(ActionServlet.java:944)

at org.apache.struts.action.ActionServlet.init(ActionServlet.java:468)

at javax.servlet.GenericServlet.init(GenericServlet.java:256)

at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:918)

at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:810)

at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3279)

at org.apache.catalina.core.StandardContext.start(StandardContext.java:3421)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1123)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:638)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1123)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:343)

at org.apache.catalina.core.StandardService.start(StandardService.java:388)

at org.apache.catalina.core.StandardServer.start(StandardServer.java:506)

at org.apache.catalina.startup.Catalina.start(Catalina.java:781)

at org.apache.catalina.startup.Catalina.execute(Catalina.java:681)

at org.apache.catalina.startup.Catalina.process(Catalina.java:179)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:243)

回复
Suspend 2005-03-01
stuts-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!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-source type="org.apache.commons.dbcp.BasicDataSource" key="dataSource">
<set-property value="net.sourceforge.jtds.jdbc.Driver" property="driverClassName" />
<set-property value="jdbc:jtds:sqlserver://127.0.0.1:1433;DatabaseName=TeacherInfo" property="url" />
<set-property value="10" property="maxActive" />
<set-property value="5000" property="maxWait" />
<set-property value="false" property="defaultAutoCommit" />
<set-property value="false" property="defaultReadOnly" />
<set-property value="SELECT COUNT(*) FROM DBA" property="validationQuery" />
<set-property value="sa" property="username" />
<set-property property="password" />
</data-source>
</data-sources>
<form-beans>
<form-bean name="loginActionForm" type="test.LoginActionForm" />
</form-beans>
<action-mappings>
<action name="loginActionForm" type="test.LoginAction" validate="true" input="/Login.jsp" scope="session" path="/loginAction">
<forward name="Success" path="/Main.jsp" />
</action>
</action-mappings>
</struts-config>


回复
Suspend 2005-03-01
Model:

package test;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class LoginModel {

public LoginModel() {
}

public boolean checkUser(Connection cn,LoginActionForm hyForm) throws SQLException {
PreparedStatement pst = cn.prepareStatement("select dbaID from DBA where dbaID=? and psw=?");
pst.setString(1,hyForm.getDbaName());
pst.setString(2,hyForm.getDbaPswd());
ResultSet rs = pst.executeQuery();

if (rs.next()) {
return true;
}
return false;
}
}
回复
jFresH_MaN 2005-03-01
晕,你没有配置Action
而且这个页面也没有提交
回复
Suspend 2005-03-01
Action:

package test;

import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.sql.Connection;
import javax.sql.DataSource;
import java.sql.SQLException;

public class LoginAction extends Action {
public ActionForward excute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
/**@todo: complete the business logic here, this is just a skeleton.*/
//throw new java.lang.UnsupportedOperationException("Method perform() not yet implemented.");
Connection cn = null;
DataSource ds;
boolean bl = false;
try {
ds = getDataSource(httpServletRequest,"dataSource");
cn = ds.getConnection();
LoginModel hymodel = new LoginModel();
bl = hymodel.checkUser(cn,(LoginActionForm)actionForm);
}
catch (Exception ex) {
}
finally {
try {
if (cn != null)
cn.close();
}
catch (SQLException ex1) {
}
}
if (bl) {
HttpSession hsn = httpServletRequest.getSession();
hsn.setAttribute("hy",actionForm);
return actionMapping.findForward("Success");
}
return new ActionForward(actionMapping.getInput());

}
}
回复
lovelanzhi716 2005-03-01
你的错误呢?就这个很难看出来的
回复
Suspend 2005-03-01
ActionForm:

package test;

import org.apache.struts.action.*;
import javax.servlet.http.*;

public class LoginActionForm extends ActionForm {
private String dbaName;
private String dbaPswd;
public void setDbaName(String dbaName) {
this.dbaName = dbaName;
}
public String getDbaName() {
return dbaName;
}
public void setDbaPswd(String dbaPswd) {
this.dbaPswd = dbaPswd;
}
public String getDbaPswd() {
return dbaPswd;
}
public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
/**@todo: finish this method, this is just the skeleton.*/
return null;
}
public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
dbaName = null;
dbaPswd = null;
}
}
回复
相关推荐
发帖
Java EE
创建于2007-09-28

6.6w+

社区成员

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
申请成为版主
帖子事件
创建了帖子
2005-03-01 04:29
社区公告
暂无公告