我正在创建一个 Struts-tiles 项目,具有以下基本细节

问题描述 投票:0回答:2

(1)我的欢迎页面是 web.xml 文件中列出的welcome.jsp

(2)welcome.jsp 包含一个简单的表单,用于提交到由 struts-config.xml 文件映射的操作

(3) 当表单提交到操作时,所有映射都是正确的,浏览器显示空白页面.... ??????我不知道出了什么问题,请帮助我......

(4)地址栏显示正确的网址,该网址执行了正确的操作,但仍然显示空白页面...

我在代码片段中提供我的welcome.jsp、struts-config.xml 文件、操作...

struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" 
 "http://struts.apache.org/dtds/struts-config_1_3.dtd">



<struts-config>
    <form-beans>
        <form-bean name="login1" type="aditya.bean.LoginBean"/>       
    </form-beans>
     
   <!-- <global-forwards>
    </global-forwards>--> 
    
    <!-- Action Mappings -->
    <action-mappings>

        <action path="/login" 
                type="aditya.action.LoginAction" 
                name="login1"
                parameter="method"
                />
                
        <forward name="loginadmin" path="/jsp/adminwel.jsp" />
        <forward name="loginuser" path="tuser"/>       

    </action-mappings>
    <controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>
<!--  <message-resources  parameter="ApplicationResources"  null="false"  />  -->
    <plug-in className="org.apache.struts.tiles.TilesPlugin">
    <set-property property="definitions-config" value="/WEB-INF/tiles-def.xml"/>
    <set-property property="moduleAware" value="true"/>
   </plug-in>
   
</struts-config>

欢迎.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>`
    
 <%@ taglib uri="http://struts.apache.org/tags-html" prefix="h" %> 
 
<!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>Welcome</title>
</head>
<body>
<h:form action="login.do" method="post">
<table border="5" bgcolor="cyan" align="center">
<tr><td>USER ID</td><td><h:text property="uid"/></td></tr>
<tr><td>PASSWORD</td><td><h:password property="pass"/></td></tr>
<tr><td><h:submit property="method" value="login"/></td></tr>
</table>
</h:form>
</body>
</html>

登录操作

package aditya.action;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import aditya.bean.LoginBean;



public class LoginAction extends DispatchAction {
    
    public ActionForward login(ActionMapping mapping,ActionForm form,HttpServletRequest req,HttpServletResponse res)throws ServletException
     {
         LoginBean loginBean=(LoginBean)form;
         System.out.println("in action-");
         
         if(loginBean.getUid().equalsIgnoreCase("admin")&&loginBean.getPass().equalsIgnoreCase("admin"))
          {
             return mapping.findForward("loginadmin");
          }
         else
          {
             return mapping.findForward("loginuser");
          }
        
     }
}

那里的任何人请帮助我解决我的问题....

为什么浏览器显示空白网页?????????

使用的IDE --> Eclipse

struts tiles struts-1
2个回答
0
投票

web.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>StrutsMvcProject-1</display-name>
  <welcome-file-list>
    
    <welcome-file>welcome.jsp</welcome-file>
    
  </welcome-file-list>
  
  
<servlet>
 <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>
 <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
 <servlet-name>action</servlet-name>
 <url-pattern>*.do</url-pattern>
 </servlet-mapping>
  
</web-app>


0
投票

显示空白页面是因为操作类没有返回到浏览器的结果。在 login() 操作中,代码应返回

ActionForward
实例。但它会返回
null
定义全局转发:

<global-forwards> <forward name="error" path="/error.jsp"/> </global-forwards>

动作代码:

ActionForward result; if(loginBean.getUid().equalsIgnoreCase("admin")&&loginBean.getPass().equalsIgnoreCase("admin")) { result = mapping.findForward("loginadmin"); if (result == null) return mapping.findForward("error"); } else { result = mapping.findForward("loginuser"); if (result == null) return mapping.findForward("error"); } return result;

© www.soinside.com 2019 - 2024. All rights reserved.