初學Struts,有點問題,大家看看,在頁面上輸入一個姓名,然後返回到該頁面
jsp頁面
<%@ page contentType= "text/html;charset=utf-8 " language= "java " pageEncoding= "utf-8 " %>
<%@ taglib uri= "http://jakarta.apache.org/struts/tags-html " prefix= "html " %>
<%@ taglib uri= "/tstiTagLib " prefix= "tsti " %>
<%@ taglib uri= "http://jakarta.apache.org/struts/tags-logic " prefix= "logic " %>
<%@ taglib uri= "http://jakarta.apache.org/struts/tags-bean " prefix= "bean " %>
<script>
message= <%=request.getAttribute( "message ")%> ;
if(message!= " "&&message!=null)
alert(message);
</script>
<html>
<head> <title> alert test </title>
<script language= "javascript ">
function __doPostBack(method) {
var thisForm = document.forms[0];
thisForm.method.value = method;
thisForm.submit();
}
</script>
</head>
<body>
<html:form action= "/A_action ">
<table>
<tr> <td> 姓名 </td>
<td> <html:text property= "name "/> </td>
</tr>
<tr> <td align= "center ">
<input type= "button " value= "go " onClick= "__doPostBack( 'btn_Submit ') ">
</td> </tr>
</table>
</html:form>
</body>
</html>
form為:
package tsti.ctust.aam.rgm.form;
import org.apache.struts.action.ActionForm;
/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2007/1/30
* Time: 上午 11:50:55
* To change this template use File | Settings | File Templates.
*/
public class A_form extends ActionForm {
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
private String name;
}
Action為
package tsti.ctust.aam.rgm.action;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import tsti.ctust.aam.rgm.form.A_form;
/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2007/1/30
* Time: 上午 11:53:10
* To change this template use File | Settings | File Templates.
*/
public class A_action extends DispatchAction{
public ActionForward btn_Submit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
{
A_form a_form=(A_form)form;
if(a_form.getName()!= " ")
request.setAttribute( "message ", "姓名不空 ");
return mapping.findForward( "success ");
}
}
大家看看是哪裡的問題.謝謝了先.
[解决办法]
message= <%=request.getAttribute( "message ")%> ;
改成
message= ' <%=request.getAttribute( "message ")%> ';
[解决办法]
有什么问题吗
只要在struts-config.xml里面把 "success "配了指向要去的jsp就行啦
或者直接在action里面return mapping.getInputForward();