struts2怎么拦截不到URLConnection发送的http请求
本帖最后由 afeiluo 于 2013-11-26 11:09:22 编辑 最近遇到一个很奇怪的问题 ,我通过浏览器向struts2发送一个http请求 能够成功的执行action里面指定的访问, 为什么我写了一个程序通过URLConnection来向struts2来发送同样的一个http请求 却不能执行struts2 的action里面指定的方法呀
代码如下:
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts2" extends="struts-default">
<action
name="request" class="com.afeiluo.GetRequestAction" method="getHttp">
</action>
</package>
</struts>
package com.afeiluo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.servlet.ServletInputStream;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class GetRequestAction extends ActionSupport {
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public void getHttp(){
System.out.println("username:"+username);
System.out.println("am in getHttp");
}}
URL url = new URL("http://localhost:8080/TestWeb/request?username=ooxx");
URLConnection connection = url.openConnection();