我想从 JSP 中删除脚本。在我的 JSP 中,我有一个脚本为
<%response.setContentType("text/xml");%>
我创建了一个视图 bean并创建了一个属性,HttpServletResponse response
并为此属性添加了 getter/setter。
当我试图获得响应时ViewBean
,它会以null
. 有什么建议可以避免这种情况NullPointerException
吗?
我的 JSP 代码是:
<jsp:useBean id="test" class="someBean" />
<jsp:setProperty name="test" property="*" />
<jsp:getProperty name="test" property="response" />
ViewBean 代码是:
package test.here;
import java.sql.*;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ibm.commerce.server.WcsApp;
import com.ibm.commerce.server.JSPHelper;
public class SomeBean {
String punchOutRes = null;
HttpServletResponse response;
HttpServletRequest request;
String test="Hello";
public HttpServletResponse getResponse() {
return response;
}
public void setResponse(HttpServletResponse response) {
this.response = response;
}
public HttpServletRequest getRequest() {
return request;
}
public void setRequest(HttpServletRequest request) {
this.request = request;
}
public String getPunchOutRes() {
response.setContentType("text/xml");
return "testing";
}
public String getTest(){
}
}