一个很简单的问题,请各位给看看,谢谢先
我做了一个访问数据库的小例子,但是在页面上点击提交后页面地址栏显示
http://localhost:7001/webmodule/whyaction.do 但是 页面变成空白的了,没反应了
代码如下:
package webtest;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import org.apache.struts.action.*;
import org.apache.struts.util.*;
public class Whyaction
extends Action {
public ActionForward Whysearch(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
/**@todo: complete the business logic here, this is just a skeleton.*/
String age;
Whyform whyform = (Whyform) actionForm;
System.out.println( "@@@@@@@@@@@@@@@@@@@@@ 1 @@@@@@@@@@@@@@@@@@ ");
try{
age=whyform.getAge();
Whydao whydao=new Whydao();
System.out.println( "@@@@@@@@@@@@@@@@@@@@@ 2 @@@@@@@@@@@@@@@@@@ ");
Whyvo whyvo= whydao.findbyage(age);
if (whyvo==null)
{
ActionErrors err=new ActionErrors();
err.add(err.GLOBAL_ERROR,new ActionError( "err.object.notfound ", "test "));
saveErrors(httpServletRequest,err);
}else{
whyform.setAge(whyvo.getAge());
whyform.setName(whyvo.getName());
whyform.setSex(whyvo.getSex());
}
}catch (Exception e)
{
ActionErrors err1=new ActionErrors();
err1.add(err1.GLOBAL_ERROR,new ActionError( "err.object.notfound ",e.getMessage()));
saveErrors(httpServletRequest,err1);
e.printStackTrace();
System.out.println( "@@@@@@@@@@@@@@@@@@@@@ 3 @@@@@@@@@@@@@@@@@@ ");
return actionMapping.findForward( "fail ");
}
return actionMapping.findForward( "suc ");
}
}
public Whyvo findbyage(String age) {
DataSource ds=null;
Context ctx=null;
Connection con=null;
Whyvo vo=new Whyvo();
try{
System.out.println( "################### 1 ####################### ");
ctx=new InitialContext();
ds=(javax.sql.DataSource)ctx.lookup( "dsjdatastore ");
}catch (Exception e){
System.out.println( "int err ");
}
PreparedStatement statement=null;
ResultSet resu=null;
String sql= "select age,sex,name from why where age=? ";
try {
System.out.println( "################### 2 ####################### ");
con=ds.getConnection();
statement=con.prepareStatement(sql);
statement.setString(1,age);
resu=statement.executeQuery();
if(resu.next()){
vo.setAge(resu.getString(1));
vo.setSex(resu.getString(2));
vo.setName(resu.getString(3));
}
resu.close();
statement.close();
}catch(SQLException e){
try{
resu.close();
statement.close();
con.rollback();
}catch(SQLException e1){
System.out.println( "err sql query ");
}
}finally{
try {
con.close();
}
catch (SQLException ex) {
System.out.println( "err close datasource ");
}
}
return vo;
}
struts-config.xml文件
<?xml version= "1.0 " encoding= "UTF-8 "?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN " "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd ">
<struts-config>
<form-beans>
<form-bean name= "whyform " type= "webtest.Whyform " />
</form-beans>
<action-mappings>
<action input= "/search.jsp " name= "whyform " path= "/whyaction " scope= "request " type= "webtest.Whyaction " validate= "false ">
<forward name= "fail " path= "/failure.jsp " />
<forward name= "suc " path= "/view.jsp " />
</action>
</action-mappings>
<message-resources parameter= "resources.application " />
</struts-config>
请帮忙看看,编译都没问题,我市部署到weblogic上的
[解决办法]
空页weblogic后台也要报错阿,报的什么错呀?
[解决办法]
return actionMapping.findForward( "fail ");
应该你是Return的时候,没有找到mapping里的findForward吧,这种情况下会返回一个空白页,不报错的
好好看看你的返回值是什么啊,用DEBUG跟踪一下吧
再看看struts-config.xml里面的forward配置有没有问题