大家帮我看看下面这段JSP代码
不知道错在哪里,是从书上摘抄的,是关于保存成为word文档的
<%@page contentType= "text/html "%>
<%@page pageEncoding= "UTF-8 "%>
<%@page import= "java.util.* " %>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri= "http://java.sun.com/jsp/jstl/core " prefix= "c "%>
--%>
<!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=UTF-8 ">
<title> JSP Page </title>
</head>
<body>
<h1> JSP Page </h1>
Good morning ! This is wuyong speaking !
<%--
This example uses JSTL, uncomment the taglib directive above.
To test, display the page like this: index.jsp?sayHello=true&name=Murphy
--%>
<%--
<c:if test= "${param.sayHello} ">
<!-- Let 's welcome the user ${param.name} -->
Hello ${param.name}!
</c:if>
--%>
<form name= "submit " method= "get " action= " ">
<input name= "submit " type= "submit " id= "submit " value= "ok " />
</form>
<%
String str= " ";
str = request.getParameter( "submit ") ;
out.print(str) ;
if(str==null){
}
if(str== "ok ")
{
out.print( "nonono ") ;
response.setContentType( "application/msword;charset=GB2312 ") ;
}else{
response.sendRedirect( "First.jsp ") ;
}
%>
</body>
</html>
[解决办法]
什么错误啊?
好像没错阿
[解决办法]
这个str的值是NULL,所以就会去执行response.sendRedirect( "First.jsp ") ;,因为你没有提交FORM,所以你这儿的str就是NULL,如果你想看到本页,你将response.sendRedirect( "First.jslp ");注释掉就可以了