问:
Buffered Writer .write not writing to file
This code is not writing to the file and I am unable to find why.

```<code>File file = DirectoryChooser.showDialog(fxcontroller.getPrimaryStage());
if (file != null) {
    BufferedWriter bw;
    try {
        File defaultMusicPath = new File("../defaultMusicPath.txt");
        bw = new BufferedWriter(new FileWriter(defaultMusicPath,true));
        bw.write(file.getAbsolutePath());
        System.out.println("done");
        bw.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
</code>```

This image shows the location of defaultMusicPath.txt

https://i.stack.imgur.com/8vxSO.png

This image if you look at the bottom shows that file.getAbsolutePath() is not null

Following what someone else said, I have made a minimum verifiable example here.

I simplified it and it still is not working in writing to a file:

```<code>BufferedWriter bw;
File defaultMusicPath = new File("../defaultMusicPath.txt");
try {
    bw = new BufferedWriter(new FileWriter(defaultMusicPath,true));
    bw.write("it should write this");

    bw.flush();
    bw.close();
    System.out.println("done");
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
</code>```

答:
You are selecting a location to put a file here

```<code>File file = DirectoryChooser.showDialog(fxcontroller.getPrimaryStage());
</code>```

And you are  writing into a File that is one folder outside the Eclipse project (in case that wasn't clear)

```<code>File defaultMusicPath = new File("../defaultMusicPath.txt");
bw = new BufferedWriter(new FileWriter(defaultMusicPath,true));
</code>```

Then you're writing the path of the first File object to the second File object correctly

```<code>bw.write(file.getAbsolutePath());
</code>```

And if there are no errors, then you are writing to a file, so perhaps you are needing to close and reopen the file in your editor.

Remove the relative ../ if you want to write into the Eclipse project.

Also, I'd recommend closing the writer in a finally block after the catch. Or using try-with-resources like so

```<code>File f = new File("defaultMusicPath.txt");
try (BufferedWriter bw =
        Files.newBufferedWriter(Paths.get(f.toURI()), StandardOpenOption.APPEND);
        PrintWriter out = new PrintWriter(bw)) {
    out.println("Hello, world!");
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
</code>```

Body:
This code is not writing to the file and I am unable to find why.

File file = DirectoryChooser.showDialog(fxcontroller.getPrimaryStage());
if (file != null) {
    BufferedWriter bw;
    try {
        File defaultMusicPath = new File("../defaultMusicPath.txt");
        bw = new BufferedWriter(new FileWriter(defaultMusicPath,true));
        bw.write(file.getAbsolutePath());
        System.out.println("done");
        bw.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

This image shows the location of defaultMusicPath.txt

https://i.stack.imgur.com/8vxSO.png

This image if you look at the bottom shows that file.getAbsolutePath() is not null

Following what someone else said, I have made a minimum verifiable example here.

I simplified it and it still is not working in writing to a file:

BufferedWriter bw;
File defaultMusicPath = new File("../defaultMusicPath.txt");
try {
    bw = new BufferedWriter(new FileWriter(defaultMusicPath,true));
    bw.write("it should write this");

    bw.flush();
    bw.close();
    System.out.println("done");
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Body:
You are selecting a location to put a file here

File file = DirectoryChooser.showDialog(fxcontroller.getPrimaryStage());

And you are  writing into a File that is one folder outside the Eclipse project (in case that wasn't clear)

File defaultMusicPath = new File("../defaultMusicPath.txt");
bw = new BufferedWriter(new FileWriter(defaultMusicPath,true));

Then you're writing the path of the first File object to the second File object correctly

bw.write(file.getAbsolutePath());

And if there are no errors, then you are writing to a file, so perhaps you are needing to close and reopen the file in your editor.

Remove the relative ../ if you want to write into the Eclipse project.

Also, I'd recommend closing the writer in a finally block after the catch. Or using try-with-resources like so

File f = new File("defaultMusicPath.txt");
try (BufferedWriter bw =
        Files.newBufferedWriter(Paths.get(f.toURI()), StandardOpenOption.APPEND);
        PrintWriter out = new PrintWriter(bw)) {
    out.println("Hello, world!");
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}


来源: stackexchange

问:
Need help populating nesting arrays in mongoose
I am struggling with populating nested arrays using mongoose.

I have a recipe model that looks something like this:

```<code>let recipeSchema = Schema({

  name: {
    type: String,
    required: true
  },

  description: {
    type: String,
  },

  steps: {
    type: String,
    required: true,
  },

  ingredients: [],

  reviewsArray: [{ type: Schema.Types.ObjectId, ref: 'Review' }],

  category: {
    type: String,
    required: true,
  },

  postedBy: [{type: Schema.Types.ObjectId, ref: 'User'}],

  numberOfRatings: {
    type: Number,
    default: 0
  },

  totalAddedRatings: {
      type: Number,
      default: 0
  },

  reviewAverage: {
      type: Number,
      default: undefined
  },

});
</code>```

And I also have a User model:

```<code>let User = Schema({

  name: {
    type: String
  },

  // The passport plugin already inputs username and password into our Schema

  username: {
    type: String,
    unique: true,
    required: true
  },

   password: {
   type: String,
   required: true,
   minlength: 6
   },

   userId: {
     type: String,
     default: "Empty"
   },

   tokens: [{

    access: {
      type: String,
      required: true
    },

    token: {
      type: String,
      required: true
    }

  }],

  profilePic: {
    type: String
  },

  email: {
    type: String,
    unique: true,
    required: true,
    validate: {
      validator: (value) => {
        return validator.isEmail(value);
      },

      message: `{value} is not a valid email address.`
    }
  },

  admin: {
    type: Boolean,
      defualt: false
  },

  usersRecipes: [{ type: Schema.Types.ObjectId, ref: 'Recipe' }],

  usersReviews: [{ type: Schema.Types.ObjectId, ref: 'Review' }],

  usersFavouriteRecipes: {
    type: Array
  },

  usersLikedRecipes: {
    type: Array
  },

  chefKarma: {
    type: Number,
    defualt: 0
  }

});
</code>```

Whenever the user makes a new recipe, I want that recipe to also be stored in the usersRecipe array. The code where I try to do that is this:

```<code>router.post('/addrecipe', (req, res, next) => {

    Recipe.create({
        name: req.body.name,
        description: req.body.description,
        steps: req.body.steps,
        ingredients: req.body.ingredients,
        category: req.body.category,
        postedBy: req.body.postedBy
    });

    User.find({_id: req.body.postedBy})
        .populate({
            path: 'usersRecipes',
            model: 'Recipe'
        })
        .exec(function(err, docs) {});

    });
</code>```

My code is not working as I intended though. Can anyone explain to me what I am doing wrong?

答:
this is what you are doing...
save a Recipe like

```<code>{
        name: "hot chips",
        description: "some goods",
        steps: "2",
        ingredients: "",
        category: "chips",
        postedBy: "12312312312312"
}
</code>```

then search for user with  12312312312312 id , some user like this

```<code>{
   name:"farshad",
   usersRecipes: []
}
</code>```

and then say populate usersRecipes for me...
do you get your mistake?
you dont write that Recipe id in you user document. so userRecipes is always empty... so each time, you dont get any usersRecipes.

you have two solution
1. when ever a user create a recipe, write that recipe id in usersRecipes...
you can create...

```<code>recipe.save().then(function(res) {
   //update user document userrecipes array
});
</code>```

OR
2.every time you get the user, search in recipes collection for recipes with that user id

```<code>Users.find({id:""}).exec(function(err, user) {
    if (err) throw err;
//fill userrecipes
    Recipes.find()....
});
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I am struggling with populating nested arrays using mongoose.

I have a recipe model that looks something like this:

let recipeSchema = Schema({

  name: {
    type: String,
    required: true
  },

  description: {
    type: String,
  },

  steps: {
    type: String,
    required: true,
  },

  ingredients: [],

  reviewsArray: [{ type: Schema.Types.ObjectId, ref: 'Review' }],

  category: {
    type: String,
    required: true,
  },

  postedBy: [{type: Schema.Types.ObjectId, ref: 'User'}],

  numberOfRatings: {
    type: Number,
    default: 0
  },

  totalAddedRatings: {
      type: Number,
      default: 0
  },

  reviewAverage: {
      type: Number,
      default: undefined
  },

});

And I also have a User model:

let User = Schema({

  name: {
    type: String
  },

  // The passport plugin already inputs username and password into our Schema

  username: {
    type: String,
    unique: true,
    required: true
  },

   password: {
   type: String,
   required: true,
   minlength: 6
   },

   userId: {
     type: String,
     default: "Empty"
   },

   tokens: [{

    access: {
      type: String,
      required: true
    },

    token: {
      type: String,
      required: true
    }

  }],

  profilePic: {
    type: String
  },

  email: {
    type: String,
    unique: true,
    required: true,
    validate: {
      validator: (value) => {
        return validator.isEmail(value);
      },

      message: `{value} is not a valid email address.`
    }
  },

  admin: {
    type: Boolean,
      defualt: false
  },

  usersRecipes: [{ type: Schema.Types.ObjectId, ref: 'Recipe' }],

  usersReviews: [{ type: Schema.Types.ObjectId, ref: 'Review' }],

  usersFavouriteRecipes: {
    type: Array
  },

  usersLikedRecipes: {
    type: Array
  },

  chefKarma: {
    type: Number,
    defualt: 0
  }

});

Whenever the user makes a new recipe, I want that recipe to also be stored in the usersRecipe array. The code where I try to do that is this:

router.post('/addrecipe', (req, res, next) => {

    Recipe.create({
        name: req.body.name,
        description: req.body.description,
        steps: req.body.steps,
        ingredients: req.body.ingredients,
        category: req.body.category,
        postedBy: req.body.postedBy
    });

    User.find({_id: req.body.postedBy})
        .populate({
            path: 'usersRecipes',
            model: 'Recipe'
        })
        .exec(function(err, docs) {});

    });

My code is not working as I intended though. Can anyone explain to me what I am doing wrong?

Body:
this is what you are doing...
save a Recipe like

{
        name: "hot chips",
        description: "some goods",
        steps: "2",
        ingredients: "",
        category: "chips",
        postedBy: "12312312312312"
}

then search for user with  12312312312312 id , some user like this

{
   name:"farshad",
   usersRecipes: []
}

and then say populate usersRecipes for me...
do you get your mistake?
you dont write that Recipe id in you user document. so userRecipes is always empty... so each time, you dont get any usersRecipes.

you have two solution
1. when ever a user create a recipe, write that recipe id in usersRecipes...
you can create...

recipe.save().then(function(res) {
   //update user document userrecipes array
});

OR
2.every time you get the user, search in recipes collection for recipes with that user id

Users.find({id:""}).exec(function(err, user) {
    if (err) throw err;
//fill userrecipes
    Recipes.find()....
});


问:
Uploading files with Python to a cloud
I would like to upload .pdf reports of data, generated in python (on a raspberry pi), onto a cloud that would make the files available through the Internet to other users.

I would like to know what would be the best way to do this. I know that the question is kind of odd, but I have no idea how to establish a direct connection from the point of generating the report, to the web server or cloud, where the data could be collected from...

I've tried using ownCloud, but wasnt able to establish a connection using the pyocclient module. If there is a way to upload files with Python to Google cloud or any other free clouds, I would be glad if anyone could explain me how to do it...

Thank you in advance for any given suggestions,
Regards,

L

答: When ever I deal with anything web related (maps, calendar, cloud storage, ect). I look at google first. Google has a wide variety of tools available for developers including one to manage a google drive. https://developers.google.com/drive/v3/web/quickstart/python is a quick start on using python to access the google cloud. It supplies a step by step tutorial on connecting to google. https://developers.google.com/drive/v3/web/manage-uploads gives a set by step guide on uploading a file using a variety of languages (including python). Hope this helps! </p>

Title: Uploading files with Python to a cloud


问:
Git (bitbucket) creating backup version
I am wondering what the standard procedure is to create an easy to find stable backup version of a git project. Ideally, it should not be necessary to go through the git logs, find a certain version and revert. Ideally, a version would be tagged. I saw git (I am using bitbucket) allows to create branches and some of those branches seem to have a tag release which In like because it indicates it is a stable version. Is branching out and switching back to the main branch for further a good way to manage this or are there better solutions available. I am not very familiar with git and its mechanics, so I would be happy to get some pointers towards good conventions.</p>

答:
I'm sure there will be others with more complete answers, but here are some tips:

Git != Bitbucket. Git is the version control system, Bitbucket is a git project hosting platform. You could just as easily work with a git repository hosted on bitbucket, github, a vps, or your local computer. Bitbucket adds a nice user interface for viewing 'releases' and such, but underneath it is all just git.

Yes, tagging and branching are major things used:

tagging: any commit in git can be tagged. These tags can then be used as references. You could make tags like v1.1, v1-stable, v1-beta to indicate stable or testing versions, etc. Usually used for marking particular revisions for various purposes (often releases).

branches: these are parallel sequences of commits - many projects use something like a stable master branch where commits are only merged to it when thoroughly tested, and a dev branch where main development happens on. Used for tracking development, especially when adding new features that require multiple commits, or trying out something different that you don't want in master.

You can 'checkout' any commit, tag, branch, etc. on your computer, which sets all the tracked files to their state as they were at that point. This means that whatever system of branching/tagging you use, you can always revert back to any commit/tag/branch you want.

Have a look at how other projects manage this. For example, the rust project on GitHub. They have multiple branches (eg. stable, master, beta), and releases are tagged (eg. 1.0.0-beta, 1.5.0).

Version control is a huge topic, and no single 'best' way to manage development. I'd suggest reading up on it (vcs in general, and the functions git gives), looking around at other projects, and most of all, jumping in and trying things yourself. Sooner or later you'll settle on a workflow that suits you or your projects' development style, whether it be tagging, branching, other features, or a combination of all.

Title: Git (bitbucket) creating backup version


问:
Access Values In Nested Array in JSON response
I have a multidimensional JSON array returned via a web request (http://www.coincap.io/history/365day/BTC). I want to cycle through the 2nd entry and retrieve its nested values.

If this was a normal array, I'd use:

```<code>For Each item In response
    logic, logic, logic

    currentRow = currentRow + 1
Next
</code>```

This web request returns a JSON-response with 3 entries: market_cap, price, and volume. I just want to cycle through response(1) and get the price values. Each entry in price contains two keys, 0 and 1.

I would imagine that I could accomplish this by doing

```<code>For Each item in response(1)
    Cells(currentRow, 1).Value = item(0)
    Cells(currentRow, 2).Value = item(1)

    currentRow = currentRow + 1
Next
</code>```

I've also considered For Each item in response("price"). Neither works.

答:
```<code>Sub Tester()

    Dim json As String
    Dim sc As Object
    Dim o, n, i, p

    Set sc = CreateObject("scriptcontrol")
    sc.Language = "JScript"

    json = HttpGet("http://www.coincap.io/history/365day/BTC")

    sc.Eval "var obj=(" & json & ")" 'evaluate the json response
    'add a couple of accessor functions
    sc.AddCode "function numPrices(){return obj.price.length;}"
    sc.AddCode "function getPrice(i){return obj.price[i];}"

    n = sc.Run("numPrices")
    For i = 0 To n - 1
        p = Split(sc.Run("getPrice", i), ",")
        Debug.Print i, p(0), p(1)
    Next i

End Sub

Function HttpGet(url As String) As String
    Dim oHTML As Object
    Set oHTML = CreateObject("Microsoft.XMLHTTP")
    With oHTML
        .Open "GET", url, False
        .send
        HttpGet = .responsetext
    End With
End Function
</code>```

Body:
I have a multidimensional JSON array returned via a web request (http://www.coincap.io/history/365day/BTC). I want to cycle through the 2nd entry and retrieve its nested values.

If this was a normal array, I'd use:

For Each item In response
    logic, logic, logic

    currentRow = currentRow + 1
Next

This web request returns a JSON-response with 3 entries: market_cap, price, and volume. I just want to cycle through response(1) and get the price values. Each entry in price contains two keys, 0 and 1.

I would imagine that I could accomplish this by doing

For Each item in response(1)
    Cells(currentRow, 1).Value = item(0)
    Cells(currentRow, 2).Value = item(1)

    currentRow = currentRow + 1
Next

I've also considered For Each item in response("price"). Neither works.


答:
You can add a tag and push it to the remote:

```<code>git tag <tagname>
git push origin --tags
</code>```

This would tag the current commit and push that new tag to the remote you cloned from. Checking out a particular branch or commit would let you tag that using this same mechanism. As stated in other answers, deciding on your tagging strategy is a different matter altogether, but this is the mechanism you use to create the tag and distribute it.

Title: Git (bitbucket) creating backup version

Body: I am wondering what the standard procedure is to create an easy to find stable backup version of a git project. Ideally, it should not be necessary to go through the git logs, find a certain version and revert. Ideally, a version would be tagged. I saw git (I am using bitbucket) allows to create branches and some of those branches seem to have a tag release which In like because it indicates it is a stable version. Is branching out and switching back to the main branch for further a good way to manage this or are there better solutions available. I am not very familiar with git and its mechanics, so I would be happy to get some pointers towards good conventions.

Body:
You can add a tag and push it to the remote:

git tag <tagname>
git push origin --tags

This would tag the current commit and push that new tag to the remote you cloned from. Checking out a particular branch or commit would let you tag that using this same mechanism. As stated in other answers, deciding on your tagging strategy is a different matter altogether, but this is the mechanism you use to create the tag and distribute it.


问:
How i can group my @Html.RadioButtonFor according to the Item foreign key value
I have 2 models inside my asp.net mvc-5 web application:-

```<code>public partial class Anwer
    {
        public Anwer()
        {
            this.UserFormsAnswers = new HashSet<UserFormsAnswer>();
        }

        public int Id { get; set; }
        public string AnwerDesc { get; set; }
        public int QuestionID { get; set; }
        public bool Correct { get; set; }

        public virtual Question Question { get; set; }
        public virtual ICollection<UserFormsAnswer> UserFormsAnswers { get; set; }
    }

 public partial class Question
    {
        public Question()
        {
            this.Anwers = new HashSet<Anwer>();
        }

        public int Id { get; set; }
        public string QuestionDesc { get; set; }
        public int Order { get; set; }
        public bool Active { get; set; }

        public virtual ICollection<Anwer> Anwers { get; set; }
    }
</code>```

now i want to show all the questions inside the view and for each question to show its answers in a radio buttons, so i tried the following:-

```<code>@model IEnumerable<QuestionsDemo.Models.Question>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">

        @{int i = 0;

            foreach (var item in Model)
{
                <div class="form-group">
                    @(i+1) <spn>-</spn> @Html.DisplayFor(modelItem => item.QuestionDesc) <br />
                    @foreach (var answer in item.Anwers)
        {
                        <div class="col-md-10">
                            @Html.RadioButtonFor(modelitem2 => answer.QuestionID, answer.Id) @answer.AnwerDesc  <br />
                        </div>
        }
                </div><hr/>
}

        }
    </div>
}
</code>```

I thought that all the answers' radio buttons for a question will have the same name. so users can only select one option for each question. but seems all the answers radio-buttons got the same name as follow:-

```<code><input id="answer_QuestionID" name="answer.QuestionID" type="radio" value="1" /> 10  <br />
</code>```

so can any one adivce on this ? how i can group the radio buttons per question?

second question. how i can post back all the answers ids to my post action method? should i use indexer ??

答:
You cannot use a foreach loop to generate the form controls for Question. You need to use a for loop, or better a custom EditorTemplate for typeof Question. Refer Post an HTML Table to ADO.NET DataTable for a detailed explanation.

Your Question model also needs a property to bind the selected Answer to, for example

```<code>public class Question
{
    public int Id { get; set; }
    ....
    public int SelectedAnswer { get; set; }
}
</code>```

And note that your editing data so you should be creating view models for both Question and Answer, not using data models in your view.

Create a partial view Views/Shared/EditorTemplates/QuestionVM.cshtml with the following code

```<code>@model QuestionsDemo.Models.Question

@Html.HiddenFor(m => m.Id)
// Add additional hidden inputs for any properties of Question that you want to be posted
@Html.DisplayFor(m => m.QuestionDesc)
@foreach(var answer in Model.Anwers)
{
    <label>
        @Html.RadioButtonFor(m => m.SelectedAnswer, answer.Id, new { id = "" })
        <span>@answer.AnwerDesc</span>
    </label>
}
</code>```

Then the main view will be

```<code>@model IEnumerable<QuestionsDemo.Models.Question>
....
@using (Html.BeginForm())
{
    ....
    @Html.EditorFor(m => m)
    <input type="submit" value="Save" />
}
</code>```

Note the EditorFor() method will correctly generate the html for each item in the collection.

Body:
I have 2 models inside my asp.net mvc-5 web application:-

public partial class Anwer
    {
        public Anwer()
        {
            this.UserFormsAnswers = new HashSet<UserFormsAnswer>();
        }

        public int Id { get; set; }
        public string AnwerDesc { get; set; }
        public int QuestionID { get; set; }
        public bool Correct { get; set; }

        public virtual Question Question { get; set; }
        public virtual ICollection<UserFormsAnswer> UserFormsAnswers { get; set; }
    }

 public partial class Question
    {
        public Question()
        {
            this.Anwers = new HashSet<Anwer>();
        }

        public int Id { get; set; }
        public string QuestionDesc { get; set; }
        public int Order { get; set; }
        public bool Active { get; set; }

        public virtual ICollection<Anwer> Anwers { get; set; }
    }

now i want to show all the questions inside the view and for each question to show its answers in a radio buttons, so i tried the following:-

@model IEnumerable<QuestionsDemo.Models.Question>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

        @{int i = 0;

            foreach (var item in Model)
{

                    @(i+1) <spn>-</spn> @Html.DisplayFor(modelItem => item.QuestionDesc)

                    @foreach (var answer in item.Anwers)
        {

                            @Html.RadioButtonFor(modelitem2 => answer.QuestionID, answer.Id) @answer.AnwerDesc

        }

}

        }

}

I thought that all the answers' radio buttons for a question will have the same name. so users can only select one option for each question. but seems all the answers radio-buttons got the same name as follow:-

<input id="answer_QuestionID" name="answer.QuestionID" type="radio" value="1" /> 10

so can any one adivce on this ? how i can group the radio buttons per question?

second question. how i can post back all the answers ids to my post action method? should i use indexer ??

Body:
You cannot use a foreach loop to generate the form controls for Question. You need to use a for loop, or better a custom EditorTemplate for typeof Question. Refer Post an HTML Table to ADO.NET DataTable for a detailed explanation.

Your Question model also needs a property to bind the selected Answer to, for example

public class Question
{
    public int Id { get; set; }
    ....
    public int SelectedAnswer { get; set; }
}

And note that your editing data so you should be creating view models for both Question and Answer, not using data models in your view.

Create a partial view Views/Shared/EditorTemplates/QuestionVM.cshtml with the following code

@model QuestionsDemo.Models.Question

@Html.HiddenFor(m => m.Id)
// Add additional hidden inputs for any properties of Question that you want to be posted
@Html.DisplayFor(m => m.QuestionDesc)
@foreach(var answer in Model.Anwers)
{
    <label>
        @Html.RadioButtonFor(m => m.SelectedAnswer, answer.Id, new { id = "" })
        <span>@answer.AnwerDesc</span>
    </label>
}

Then the main view will be

@model IEnumerable<QuestionsDemo.Models.Question>
....
@using (Html.BeginForm())
{
    ....
    @Html.EditorFor(m => m)
    <input type="submit" value="Save" />
}

Note the EditorFor() method will correctly generate the html for each item in the collection.


问:
How can I pass command-line arguments via file association in Vista 64?
How can one pass command line arguments via file association in Vista 64?

I recently built a PC running Vista Ultimate 64-bit.  I noticed several of the Perl scripts I transferred failed due to command-line arguments not being passed.  As a simple test, I wrote the following (foo.pl):

```<code>#!/usr/bin/perl -w
use strict;
my $num_args = $#ARGV + 1;
print "${num_args} arguments read\n";
print "$^X\n" # to see what was being used
</code>```

Running "foo.pl 1 2 3" undesirably yielded:

```<code>0 arguments read
C:\strawberry\perl\bin\perl.exe
</code>```

Running "perl foo.pl 1 2 3" expectedly yielded:

```<code>3 arguments read
C:\strawberry\perl\bin\perl.exe
</code>```

On my old Windows XP PC, both invocations returned 3 arguments.  I documented more of my sleuthing here (win32.perl.org wiki talk), but I've yet to find a solution that works.

I've also tried ActivePerl-5.10.0.1004-MSWin32-x64-287188.msi to no avail.

Any help would be appreciated.  This is driving me batty.

答: Vista's file extension manager removed the ability to pass arguments to programs.  You have to manually edit the registry like devio mentions (or use another program to edit file extensions).</p>

ContentLicense: CC BY-SA 2.5

Body:
How can one pass command line arguments via file association in Vista 64?

I recently built a PC running Vista Ultimate 64-bit.  I noticed several of the Perl scripts I transferred failed due to command-line arguments not being passed.  As a simple test, I wrote the following (foo.pl):

#!/usr/bin/perl -w
use strict;
my $num_args = $#ARGV + 1;
print "${num_args} arguments read\n";
print "$^X\n" # to see what was being used

Running "foo.pl 1 2 3" undesirably yielded:

0 arguments read
C:\strawberry\perl\bin\perl.exe

Running "perl foo.pl 1 2 3" expectedly yielded:

3 arguments read
C:\strawberry\perl\bin\perl.exe

On my old Windows XP PC, both invocations returned 3 arguments.  I documented more of my sleuthing here (win32.perl.org wiki talk), but I've yet to find a solution that works.

I've also tried ActivePerl-5.10.0.1004-MSWin32-x64-287188.msi to no avail.

Any help would be appreciated.  This is driving me batty.

LastEditorDisplayName: Kurt Leucht

OwnerDisplayName: R. Bemrose


问:
is guice-struts2-plugin-2.0 support the Struts 2.x?
I am using Guice 2.0 and its struts plugin 'guice-struts2-plugin-2.0' in my application. The struts version is 'Struts2-core-2.1.8.1 and application server is Jboss 4.2.2.
when deploying application getting problem

```<code>java.lang.NullPointerException :  at com.google.inject.struts2.GuiceObjectFactory
$ProvidedInterceptor.destroy(GuiceObjectFactory.java:216)
here is my stack trace

23:06:11,390 INFO  [TomcatDeployer] deploy, ctxPath=/
HelloGuiceServlet, warUrl=.../tmp/deploy/tmp2295HelloGuiceServlet-
exp.war/
23:06:11,390 INFO  [ContainerBase] Container
org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/
HelloGuiceServlet].[jsp] has not been started
23:06:11,390 INFO  [ContainerBase] Container
org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/
HelloGuiceServlet].[default] has not been started
23:06:11,390 ERROR [BaseModelMBean] Exception invoking method destroy
java.lang.NullPointerException
       at com.google.inject.struts2.GuiceObjectFactory
$ProvidedInterceptor.destroy(GuiceObjectFactory.java:216)
       at org.apache.struts2.dispatcher.Dispatcher.cleanup(Dispatcher.java:
298)
       at
org.apache.struts2.dispatcher.ng.PrepareOperations.cleanupDispatcher(PrepareOperations.java:
179)
       at
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.destroy(StrutsPrepareAndExecuteFilter.java:
100)
       at
org.apache.catalina.core.ApplicationFilterConfig.release(ApplicationFilterConfig.java:
332)
       at
org.apache.catalina.core.StandardContext.filterStop(StandardContext.java:
3757)
       at org.apache.catalina.core.StandardContext.stop(StandardContext.java:
4517)
       at org.apache.catalina.core.ContainerBase.destroy(ContainerBase.java:
1163)
       at
org.apache.catalina.core.StandardContext.destroy(StandardContext.java:
4617)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:
296)
       at
org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:
164)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at
org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:
175)
       at
org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:
104)
       at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:
375)
       at org.jboss.web.WebModule.startModule(WebModule.java:83)
       at org.jboss.web.WebModule.startService(WebModule.java:61)
       at
org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:
289)
       at
org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:
245)
       at sun.reflect.GeneratedMethodAccessor94.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:
155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:
264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at org.jboss.system.ServiceController
$ServiceProxy.invoke(ServiceController.java:978)
       at $Proxy0.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:
417)
       at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:
155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:
264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy44.start(Unknown Source)
       at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:
466)
       at sun.reflect.GeneratedMethodAccessor93.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:
155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at
org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:
133)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at
org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:
142)
       at
org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:
97)
       at
org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:
238)
       at
org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:
87)
       at org.jboss.deployment.SubDeployerInterceptorSupport
$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
       at
org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:
95)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:
264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy45.start(Unknown Source)
       at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
       at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:
155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at
org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:
133)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at
org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:
142)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:
264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy9.deploy(Unknown Source)
       at
org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:
421)
       at
org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:
610)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner
$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner
$ScannerThread.loop(AbstractDeploymentScanner.java:274)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner
$ScannerThread.run(AbstractDeploymentScanner.java:225)
23:06:11,406 WARN  [ServiceController] Problem starting service
jboss.web.deployment:war=HelloGuiceServlet.war,id=-343052674
org.jboss.deployment.DeploymentException: Error during deploy; -
nested throwable: (javax.management.RuntimeOperationsException:
Exception invoking method destroy)
       at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:
384)
       at org.jboss.web.WebModule.startModule(WebModule.java:83)
       at org.jboss.web.WebModule.startService(WebModule.java:61)
       at
org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:
289)
       at
org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:
245)
       at sun.reflect.GeneratedMethodAccessor94.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:
155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:
264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at org.jboss.system.ServiceController
$ServiceProxy.invoke(ServiceController.java:978)
       at $Proxy0.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:
417)
       at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:
155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:
264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy44.start(Unknown Source)
       at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:
466)
       at sun.reflect.GeneratedMethodAccessor93.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:
155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at
org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:
133)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at
org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:
142)
       at
org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:
97)
       at
org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:
238)
       at
org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:
87)
       at org.jboss.deployment.SubDeployerInterceptorSupport
$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
       at
org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:
95)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:
264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy45.start(Unknown Source)
       at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
       at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:
155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at
org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:
133)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at
org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:
142)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:
264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy9.deploy(Unknown Source)
       at
org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:
421)
       at
org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:
610)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner
$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner
$ScannerThread.loop(AbstractDeploymentScanner.java:274)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner
$ScannerThread.run(AbstractDeploymentScanner.java:225)
Caused by: javax.management.RuntimeOperationsException: Exception
invoking method destroy
       at
org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:
304)
       at
org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:
164)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at
org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:
175)
       at
org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:
104)
       at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:
375)
       ... 65 more
Caused by: java.lang.NullPointerException
       at com.google.inject.struts2.GuiceObjectFactory
$ProvidedInterceptor.destroy(GuiceObjectFactory.java:216)
       at org.apache.struts2.dispatcher.Dispatcher.cleanup(Dispatcher.java:
298)
       at
org.apache.struts2.dispatcher.ng.PrepareOperations.cleanupDispatcher(PrepareOperations.java:
179)
       at
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.destroy(StrutsPrepareAndExecuteFilter.java:
100)
       at
org.apache.catalina.core.ApplicationFilterConfig.release(ApplicationFilterConfig.java:
332)
       at
org.apache.catalina.core.StandardContext.filterStop(StandardContext.java:
3757)
       at org.apache.catalina.core.StandardContext.stop(StandardContext.java:
4517)
       at org.apache.catalina.core.ContainerBase.destroy(ContainerBase.java:
1163)
       at
org.apache.catalina.core.StandardContext.destroy(StandardContext.java:
4617)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:
296)
       ... 70 more
</code>```

Is really google guice supports the Struts2Integration ??? is guice-struts2-plugin-2.0 is mature plugin for struts ???

Any Help Please.

答: The guice wiki page is an example of using guice with struts 2.2 and up. It looks like you are using struts 2.1.8.1 so that example won't work for you. I had the same problem but was able to use guice with struts < 2.2 by using the example on the source code. Its a little more work but it does work.</p>

Body:
I am using Guice 2.0 and its struts plugin 'guice-struts2-plugin-2.0' in my application. The struts version is 'Struts2-core-2.1.8.1 and application server is Jboss 4.2.2.
when deploying application getting problem

java.lang.NullPointerException :  at com.google.inject.struts2.GuiceObjectFactory
$ProvidedInterceptor.destroy(GuiceObjectFactory.java:216)
here is my stack trace

23:06:11,390 INFO  [TomcatDeployer] deploy, ctxPath=/
HelloGuiceServlet, warUrl=.../tmp/deploy/tmp2295HelloGuiceServlet-
exp.war/
23:06:11,390 INFO  [ContainerBase] Container
org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/
HelloGuiceServlet].[jsp] has not been started
23:06:11,390 INFO  [ContainerBase] Container
org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/
HelloGuiceServlet].[default] has not been started
23:06:11,390 ERROR [BaseModelMBean] Exception invoking method destroy
java.lang.NullPointerException
       at com.google.inject.struts2.GuiceObjectFactory
$ProvidedInterceptor.destroy(GuiceObjectFactory.java:216)
       at org.apache.struts2.dispatcher.Dispatcher.cleanup(Dispatcher.java:
298)
       at
org.apache.struts2.dispatcher.ng.PrepareOperations.cleanupDispatcher(PrepareOperations.java:
179)
       at
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.destroy(StrutsPrepareAndExecuteFilter.java:
100)
       at
org.apache.catalina.core.ApplicationFilterConfig.release(ApplicationFilterConfig.java:
332)
       at
org.apache.catalina.core.StandardContext.filterStop(StandardContext.java:
3757)
       at org.apache.catalina.core.StandardContext.stop(StandardContext.java:
4517)
       at org.apache.catalina.core.ContainerBase.destroy(ContainerBase.java:
1163)
       at
org.apache.catalina.core.StandardContext.destroy(StandardContext.java:
4617)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:
296)
       at
org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:
164)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at
org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:
175)
       at
org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:
104)
       at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:
375)
       at org.jboss.web.WebModule.startModule(WebModule.java:83)
       at org.jboss.web.WebModule.startService(WebModule.java:61)
       at
org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:
289)
       at
org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:
245)
       at sun.reflect.GeneratedMethodAccessor94.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:
155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:
264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at org.jboss.system.ServiceController
$ServiceProxy.invoke(ServiceController.java:978)
       at $Proxy0.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:
417)
       at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:
155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:
264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy44.start(Unknown Source)
       at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:
466)
       at sun.reflect.GeneratedMethodAccessor93.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:
155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at
org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:
133)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at
org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:
142)
       at
org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:
97)
       at
org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:
238)
       at
org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:
87)
       at org.jboss.deployment.SubDeployerInterceptorSupport
$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
       at
org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:
95)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:
264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy45.start(Unknown Source)
       at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
       at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:
155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at
org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:
133)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at
org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:
142)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:
264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy9.deploy(Unknown Source)
       at
org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:
421)
       at
org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:
610)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner
$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner
$ScannerThread.loop(AbstractDeploymentScanner.java:274)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner
$ScannerThread.run(AbstractDeploymentScanner.java:225)
23:06:11,406 WARN  [ServiceController] Problem starting service
jboss.web.deployment:war=HelloGuiceServlet.war,id=-343052674
org.jboss.deployment.DeploymentException: Error during deploy; -
nested throwable: (javax.management.RuntimeOperationsException:
Exception invoking method destroy)
       at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:
384)
       at org.jboss.web.WebModule.startModule(WebModule.java:83)
       at org.jboss.web.WebModule.startService(WebModule.java:61)
       at
org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:
289)
       at
org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:
245)
       at sun.reflect.GeneratedMethodAccessor94.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:
155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:
264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at org.jboss.system.ServiceController
$ServiceProxy.invoke(ServiceController.java:978)
       at $Proxy0.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:
417)
       at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:
155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:
264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy44.start(Unknown Source)
       at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:
466)
       at sun.reflect.GeneratedMethodAccessor93.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:
155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at
org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:
133)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at
org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:
142)
       at
org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:
97)
       at
org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:
238)
       at
org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:
87)
       at org.jboss.deployment.SubDeployerInterceptorSupport
$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
       at
org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:
95)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:
264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy45.start(Unknown Source)
       at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
       at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:
155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at
org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:
133)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at
org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:
142)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
       at
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:
264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy9.deploy(Unknown Source)
       at
org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:
421)
       at
org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:
610)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner
$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner
$ScannerThread.loop(AbstractDeploymentScanner.java:274)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner
$ScannerThread.run(AbstractDeploymentScanner.java:225)
Caused by: javax.management.RuntimeOperationsException: Exception
invoking method destroy
       at
org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:
304)
       at
org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:
164)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:
659)
       at
org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:
175)
       at
org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:
104)
       at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:
375)
       ... 65 more
Caused by: java.lang.NullPointerException
       at com.google.inject.struts2.GuiceObjectFactory
$ProvidedInterceptor.destroy(GuiceObjectFactory.java:216)
       at org.apache.struts2.dispatcher.Dispatcher.cleanup(Dispatcher.java:
298)
       at
org.apache.struts2.dispatcher.ng.PrepareOperations.cleanupDispatcher(PrepareOperations.java:
179)
       at
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.destroy(StrutsPrepareAndExecuteFilter.java:
100)
       at
org.apache.catalina.core.ApplicationFilterConfig.release(ApplicationFilterConfig.java:
332)
       at
org.apache.catalina.core.StandardContext.filterStop(StandardContext.java:
3757)
       at org.apache.catalina.core.StandardContext.stop(StandardContext.java:
4517)
       at org.apache.catalina.core.ContainerBase.destroy(ContainerBase.java:
1163)
       at
org.apache.catalina.core.StandardContext.destroy(StandardContext.java:
4617)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at
org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:
296)
       ... 70 more

Is really google guice supports the Struts2Integration ??? is guice-struts2-plugin-2.0 is mature plugin for struts ???

Any Help Please.


问:
can we retrieve and set PHP cookies using javascriopt
I've set a cookie using PHP,

```<code>setcookie("redirect", $this->currentPage(), time() + 31536000);
</code>```

but I want to retrieve the value of this cookie using javascript when a certain link is clicked. How can I do that?

答:
Here's another take that attempts to be easier to understand.

Also, since cookies are encoded (both keys and values), you will want to decode them both.

```<code>var getCookie = function(name) {

    var thisCookie,
        keyValuePair,
        key,
        value,
        cookies = document.cookie.split('; ') ;

    for ( var i=0 ; i<cookies.length ; i++ ) {
        thisCookie = cookies[i] ;
        keyValuePair = thisCookie.split('=') ;
        key = decodeURIComponent(keyValuePair[0]) ;
        if ( key === name ) {
            value = keyValuePair[1] ;
            return (value != null) ? decodeURIComponent(value) : null;
        }
    }
}
</code>```

Regarding the part about getting the cookie on a link click, you would call this function in an event handler.

Let's assume that you know how to get the link in question in JavaScript.  Here's one way to get the first link in the document:

```<code>var link = document.querySelector('A') ;
</code>```

In any case, once you have your link, here is how to get the value when the link is clicked:

```<code>var getCookieOnLinkClick = function() {
    var cookieValue = getCookie('cookieName') ;
    console.log('Cookie value is ', cookieValue) ;
}

link.addEventListener('click', getCookieOnLinkClick) ;
</code>```

(Of course, most links will load a new page, so you won't have much time to do anything with the cookie value once you get it.)

Body:
I've set a cookie using PHP,

setcookie("redirect", $this->currentPage(), time() + 31536000);

but I want to retrieve the value of this cookie using javascript when a certain link is clicked. How can I do that?

Body:
Here's another take that attempts to be easier to understand.

Also, since cookies are encoded (both keys and values), you will want to decode them both.

var getCookie = function(name) {

    var thisCookie,
        keyValuePair,
        key,
        value,
        cookies = document.cookie.split('; ') ;

    for ( var i=0 ; i<cookies.length ; i++ ) {
        thisCookie = cookies[i] ;
        keyValuePair = thisCookie.split('=') ;
        key = decodeURIComponent(keyValuePair[0]) ;
        if ( key === name ) {
            value = keyValuePair[1] ;
            return (value != null) ? decodeURIComponent(value) : null;
        }
    }
}

Regarding the part about getting the cookie on a link click, you would call this function in an event handler.

Let's assume that you know how to get the link in question in JavaScript.  Here's one way to get the first link in the document:

var link = document.querySelector('A') ;

In any case, once you have your link, here is how to get the value when the link is clicked:

var getCookieOnLinkClick = function() {
    var cookieValue = getCookie('cookieName') ;
    console.log('Cookie value is ', cookieValue) ;
}

link.addEventListener('click', getCookieOnLinkClick) ;

(Of course, most links will load a new page, so you won't have much time to do anything with the cookie value once you get it.)


问:
Can I link facebook's post when I make my page?
I have a question about html5 coding.

I want to link facebook page's newest post in my page.

For example, if there is a facebook page named "stackoverflow" and the page's newest post is "HTML5 question".

I want to take this "HTML5 question" post on my page, as it is.

After the newest post chages, on my page, it also changes.

Can I make it??

答: I would suggest to simply link to your facebook page. The newest post is always shown on top there.</p>