2024年5月11日发(作者:)

出现这个错误,一定是多次response导致的,例如下面这段代码就会出现此错误:

[java] view plaincopy

1. import ;

2.

3. import rvletResponse;

4.

5. import tActionContext;

6.

7. import Support;

8.

9. public class LoginAction extends ActionSupport {

10.

11. /**

12. *

13. */

14. private static final long serialVersionUID = 1L;

15. private String userName;

16. private String pwd;

17. private String verifyCode;

18. private String ajax;

19.

20. // 错误的写法

21. @Override

22. public String execute() throws Exception {

23. // 通过ajax登录

24. if (ajax != null) {

25. HttpServletResponse response = ponse(

);

26. Writer writer = ter();

27. ("登录成功!");

28. ();

29. ();

30. }

31. return SUCCESS;

32. }

33.

34. // 正确写法

35. public String login1() throws Exception {

36. if (ajax != null) {

37. HttpServletResponse response = ponse(

);

38. Writer writer = ter();

39. ("登录成功!");

40. ();

41. ();

42. return null;

43. }

44. return SUCCESS;

45. }

46.

47. // 正确写法

48. public String login2() throws Exception {

49. if (ajax != null) {

50. HttpServletResponse response = ponse(

);

51. Writer writer = ter();

52. ("登录成功!");

53. ();

54. ();

55. }

56. return null;

57. }

58.

59. public String getUserName() {

60. return userName;

61. }

62.

63. public void setUserName(String userName) {

64. me = userName;

65. }

66.

67. public String getPwd() {

68. return pwd;

69. }

70.

71. public void setPwd(String pwd) {

72. = pwd;

73. }

74.

75. public String getVerifyCode() {

76. return verifyCode;

77. }

78.

79. public void setVerifyCode(String verifyCode) {

80. Code = verifyCode;

81. }